package com.jz.jingying.service.impl;

import com.baomidou.mybatisplus.enums.SqlLike;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.jz.jingying.bean.*;
import com.jz.jingying.mapper.sqlServer.*;
import com.jz.jingying.service.JiaYingToJingYingService;
import com.jz.jingying.utils.Base64Utils;
import com.jz.jingying.utils.DateTools;
import com.jz.jingying.utils.NumberTools;
import com.jz.netthings.appengine.baseData.ProviderInfo;
import com.jz.netthings.appengine.mapper.ProviderInfoMapper;
import com.jz.netthings.application.base.bean.ProviderAddressAllowance;
import com.jz.netthings.application.base.bean.Systemlogjiaying;
import com.jz.netthings.application.base.mapper.mysql.ProviderAddressAllowanceMapper;
import com.jz.netthings.application.base.mapper.mysql.SystemlogjiayingMapper;
import com.jz.netthings.application.bodyCheck.bean.BodyCheck;
import com.jz.netthings.application.bodyCheck.mapper.mysql.BodyCheckMapper;
import com.jz.netthings.application.heatseal.bean.HeatSeal;
import com.jz.netthings.application.heatseal.mapper.mysql.HeatSealMapper;
import com.jz.netthings.application.providerAllot.bean.ProviderAllot;
import com.jz.netthings.application.providerAllot.mapper.mysql.ProviderAllotMapper;
import com.jz.netthings.application.providerCollection.bean.ExceptionCollections;
import com.jz.netthings.application.providerCollection.bean.ProviderCollection;
import com.jz.netthings.application.providerCollection.mapper.mysql.ExceptionCollectionsMapper;
import com.jz.netthings.application.providerCollection.mapper.mysql.ProviderCollectionMapper;
import com.jz.netthings.application.providerCost.bean.ProviderCost;
import com.jz.netthings.application.providerCost.mapper.mysql.ProviderCostMapper;
import com.jz.netthings.application.providerCreate.bean.ProviderXp;
import com.jz.netthings.application.providerCreate.bean.ProviderZw;
import com.jz.netthings.application.providerCreate.mapper.mysql.ProviderXpMapper;
import com.jz.netthings.application.providerCreate.mapper.mysql.ProviderZwMapper;
import com.jz.netthings.application.providerReg.bean.ProviderReg;
import com.jz.netthings.application.providerReg.mapper.mysql.ProviderRegMapper;
import com.jz.netthings.application.providerXqdy.bean.ProviderXqdyqd;
import com.jz.netthings.application.providerXqdy.mapper.mysql.ProviderXqdyqdMapper;
import com.jz.netthings.application.sample.bean.PlasmaSamples;
import com.jz.netthings.application.sample.mapper.PlasmaSamplesMapper;
import com.jz.netthings.application.upload.service.UploadService;
import com.jz.netthings.bean.system.JyUser;
import com.jz.netthings.system.mapper.mysql.JyCodeMapper;
import com.jz.netthings.system.mapper.mysql.JyUserMapper;
import com.jz.netthings.utils.AdscmBaseUtils;
import com.jz.netthings.utils.AdscmDateUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @author zyl
 * @Date 2019/4/15 -14:47
 */
@Service
public class JiaYingToJingYingServiceImpl implements JiaYingToJingYingService {

    Logger logger = Logger.getLogger(JiaYingToJingYingServiceImpl.class);
    @Autowired
    ProviderInfoMapper providerInfoMapper;
    @Autowired
    TProviderbaseinfoMapper tProviderbaseinfoMapper;
    @Autowired
    TCardtableMapper tCardtableMapper;
    @Autowired
    JyUserMapper jyUserMapper;
    @Autowired
    SystemlogjiayingMapper systemlogjiayingMapper;
    @Autowired
    ProviderRegMapper providerRegMapper;
    @Autowired
    UploadService uploadService;
    @Autowired
    ProviderZwMapper providerZwMapper;
    @Autowired
    TZwtableMapper tZwtableMapper;
    @Autowired
    TProviderregisterMapper tProviderregisterMapper;
    @Autowired
    ProviderCostMapper providerCostMapper;
    @Autowired
    ProviderAddressAllowanceMapper providerAddressAllowanceMapper;
    @Autowired
    TRegisterteminfoMapper tRegisterteminfoMapper;
    @Autowired
    BodyCheckMapper    bodyCheckMapper;
    @Autowired
    TBodycheckrecordMapper    tBodycheckrecordMapper;
    @Autowired
    PlasmaSamplesMapper plasmaSamplesMapper;
    @Autowired
    TAssayrecordMapper  tAssayrecordMapper;
    @Autowired
    TAssayrecordregisterMapper tAssayrecordregisterMapper;
    @Autowired
    HeatSealMapper heatSealMapper;
    @Autowired
    TCollectionrecordMapper tCollectionrecordMapper;
    @Autowired
    TPlasmstockabcMapper tPlasmstockabcMapper;
    @Autowired
    ProviderXpMapper providerXpMapper;
    @Autowired
    TBodychecklastrecordMapper tBodychecklastrecordMapper;
    @Autowired
    ProviderAllotMapper providerAllotMapper;
    @Autowired
    ProviderXqdyqdMapper providerXqdyqdMapper;
    @Autowired
    TAssayXqdyMapper tAssayXqdyMapper;
    @Autowired
    ProviderCollectionMapper providerCollectionMapper;
    @Autowired
    KHcslMapper  kHcslMapper;
    @Autowired
    KUseMapper kUseMapper;
    @Autowired
    KUseListMapper kUseListMapper;
    @Autowired
    ExceptionCollectionsMapper exceptionCollectionsMapper;
    @Autowired
    TRaterecordMapper tRaterecordMapper;
    @Autowired
    SysOptionterMapper  sysOptionterMapper;
    @Autowired
    JiaYingToJingYingService jiaYingToJingYingService;
     //每分钟执行一次
//    @Scheduled(cron = "0 * * * * ?")
     public void syn()throws Exception{
         logger.info("执行定时任务：从佳颖数据库同步营运流程数据到精英数据库    开始~~~~~~~~~~~~~~~~~~~~");
         /*
          * 同步建档信息
          */
         jiaYingToJingYingService.doProviderBaseInfoExec();
         /*
          * 同步登记信息
          */
         jiaYingToJingYingService.doProviderRegisterExec();
         /*
          * 同步体检信息
          */
         jiaYingToJingYingService.doBodyCheckExec();
         /*
          * 同步分配信息
          */
         jiaYingToJingYingService.doAllotExec();
         /*
          * 同步小样采集信息
          */
         jiaYingToJingYingService.doSampleCollectionExec();
         /*
          * 同步化检信息
          */
         jiaYingToJingYingService.doAssayExec();
         /*
          * 同步采浆信息
          */
         jiaYingToJingYingService.doCollectionExec();
         /*
          * 同步费用发放信息
          */
         jiaYingToJingYingService.doCostExec();
         /*
          * 同步血浆入库【热合】信息
          */
         jiaYingToJingYingService.doHeatExec();

         /*
          * 同步胸片信息
          */
         jiaYingToJingYingService.doXpExec();

         /*
          * 同步日志信息
          */
         jiaYingToJingYingService.doLogExec();
         logger.info("执行定时任务：从佳颖数据库同步营运流程数据到精英数据库    结束~~~~~~~~~~~~~~~~~~~~");
     }



    @Override
    public void doProviderBaseInfoExec() throws Exception {
        Date now = new Date();
        Date nowZero = AdscmDateUtils.getFormateDate(now);
        //查询待同步的浆员信息  modifyTime>= synDate
        Wrapper<ProviderInfo> getSynWrapper=new EntityWrapper<>();
        getSynWrapper.last("where   modifyTime>= synDate");
        List<ProviderInfo> providerInfos = providerInfoMapper.selectList(getSynWrapper);

        logger.info("待同步的供浆者信息 记录数=" + providerInfos.size());

        List<ProviderInfo> successGjz = new ArrayList<>();// 用来存储同步到精英系统成功了的浆员，然后再更新佳颖数据库中的同步状态
        for (ProviderInfo providerInfo : providerInfos) {
            try {
                logger.info("同步的供浆者【" + providerInfo.getCardId() + "-" + providerInfo.getName() + "】开始~~~");
                TProviderbaseinfo provider = new TProviderbaseinfo();
                provider.setIDNo(providerInfo.getIdNo());
                List<TProviderbaseinfo> baseInfoList = tProviderbaseinfoMapper.getProviderBaseInfo(provider);
                TCardtable cardtable = new TCardtable();
                if (baseInfoList != null && baseInfoList.size() == 1) {
                    provider = baseInfoList.get(0);

                    if (provider.getICNo() != null && provider.getICNo().length() > 0) {

                    } else {
                        if (!providerInfo.getCardId().startsWith("R") && ("".equals(provider.getICNo()) || provider.getICNo() == null) || "0".equals(provider.getICNo())) {
                            // 获取精英最大的IC卡号
                            String maxIcNo = tProviderbaseinfoMapper.getMaxIcNo();

                            int int_icno = 1;
                            try {
                                int_icno = Integer.parseInt(maxIcNo);
                            } catch (Exception e) {
                            }
                            int_icno = int_icno + 1;

                            String icno = NumberTools.getInstance().decimalFormat(int_icno, 10);
                            // 保存精英IC卡使用状态
                            cardtable.setICNo(Base64Utils.encode(icno));
                            List<TCardtable> cardList = tCardtableMapper.getCardTable(cardtable);
                            if (cardList != null && cardList.size() > 0) {
                                cardtable = cardList.get(0);
                                cardtable.setState("1");
                            }
                            provider.setICNo(icno);// IC卡号

                            logger.info("写精英的日志：发卡  start");

                            String nurse = providerInfo.getCreateNurse();
                            JyUser jyUser = jyUserMapper.selectById(nurse);
                            String optionerName = "";
                            if (AdscmBaseUtils.getInstance().isNotEmpty(jyUser, null)) {
                                optionerName = jyUser.getName();
                            }

                            int worker = 0;
                            if (nurse != null && !"".equals(nurse) && nurse.length() > 3) {
                                if (NumberTools.getInstance().isNumeric2(nurse.substring(3))) {
                                    worker = Integer.parseInt(nurse.substring(3));
                                }
                            }

                            try {

                                Systemlogjiaying sysLog = new Systemlogjiaying();
                                sysLog.setModeName("发卡");
                                String optionInfo = "操作员：" + optionerName + "把新浆员<" + providerInfo.getName() + "> 编号为："
                                        + provider.getProviderNo() + "改成编号为：" + providerInfo.getCardId() + "；并发卡号为：" + icno;
                                sysLog.setOptioninfo(optionInfo);
                                sysLog.setOptionter(worker + "");
                                sysLog.setOptionterdate(now);
                                sysLog.setOptdate(now);
                                sysLog.setOptdate(nowZero);
                                sysLog.setSynDate(nowZero);
                                sysLog.setModifyTime(now);
                                sysLog.setDelbat("0");
                                systemlogjiayingMapper.insert(sysLog);

                            } catch (Exception e) {
                                logger.info("写精英的日志：发卡  异常：" + e.getMessage());
                            }
                            logger.info("写精英的日志：发卡  end");

                        }


                    }
                } else {
                    provider.setSFFZ("0");
                    provider.setOrg_id("0");
                    provider.setUpdate_flag("2");
                    provider.setUpdate_date("1900-01-01 00:00:00");
                    provider.setWeb_flag("-1");
                    provider.setUppic_flag("0");
                    provider.setZw_downflag("0");
                    provider.setAvalue("0");
                    provider.setOrg_id_SW("0");
                    provider.setUpdate_flag_SW("2");
                    provider.setUpdate_date_SW("1900-01-01 00:00:00");
                    provider.setWeb_flag_SW("-1");
                    provider.setOrg_id_QT("0");
                    provider.setUpdate_flag_QT("0");
                    provider.setUpdate_date_QT("1900-01-01 00:00:00");
                    provider.setWeb_flag_QT("-1");
                    provider.setUppic_flag_sw("0");
                    provider.setUppic_flag_qt("0");
                    provider.setZw_downflag_sw("0");
                    provider.setZw_downflag_qt("0");
                    provider.setTrafficFee("0");
                    provider.setCJCS_0912("0");
                    provider.setCJCS_1001("0");
                    provider.setCJCS_1002("0");
                    provider.setUpdate_flag_bm("0");
                    provider.setJSRID("0");
                    provider.setNLXX("0");
                    provider.setSend_dx("否");
                    provider.setPH_IFVIP("0");

                    provider.setOLdNewRedatebz("1");

                }
                provider.setName(providerInfo.getName());
                if (providerInfo.getSex().equals("1")) {
                    provider.setSex("M");
                } else if (providerInfo.getSex().equals("2")) {
                    provider.setSex("F");
                }
                provider.setProviderNo(providerInfo.getCardId());
                //同步照片
//                if (provider.getIDCardPhoto() != null && provider.getIDCardPhoto().length > 0) {
//                } else {
                    if (AdscmBaseUtils.getInstance().isNotEmpty(providerInfo.getIdCardPhoto(), null)) {
                        byte[] photo = uploadService.downloadImageReturnBytes(providerInfo.getPhoto());

                        byte[] Idcardphoto = uploadService.downloadImageReturnBytes(providerInfo.getIdCardPhoto());
                        byte[] Idcardphoto1 = uploadService.downloadImageReturnBytes(providerInfo.getIdCardPhoto1());
                        provider.setPhoto(photo);
                        provider.setIDCardPhoto(Idcardphoto);
                        provider.setIDCardPhotoBlack(Idcardphoto1);
                    }
//                }

                provider.setBirthDay(AdscmDateUtils.getDateFomat(providerInfo.getBirthday()));
                provider.setAddress(providerInfo.getIdNoAddress());
                provider.setTel(providerInfo.getPhone());
                if (providerInfo.getProviderState() == 2) {
                    provider.setProviderState("0");
                } else {
                    provider.setProviderState("1");
                }
                provider.setFileDate(AdscmDateUtils.getNowOnlyDateFomat1(providerInfo.getCreateDate()));
                if (AdscmBaseUtils.getInstance().isNotEmpty(providerInfo.getProvideTotalTimes(),null)){

                    provider.setTimes(String.valueOf(providerInfo.getProvideTotalTimes()));
                }else {
                    provider.setTimes("0");
                }
                provider.setRegistDate(AdscmDateUtils.getDateFomat(providerInfo.getCreateDate()));
                if (AdscmBaseUtils.getInstance().isNotEmpty(providerInfo.getRefuseDate(), null)) {

                    provider.setRefuseDate(AdscmDateUtils.getDateFomat(providerInfo.getRefuseDate()));
                } else {
                    provider.setRefuseDate("1900-01-01 00:00:00");
                }
                provider.setProviderType("1");
                provider.setRefuseReason(providerInfo.getRefuseReason());

                provider.setNowAddress(providerInfo.getAddress());
                provider.setNation(String.valueOf(providerInfo.getNation()));// 民族需要添加字段到我们数据库
                if (AdscmBaseUtils.getInstance().isNotEmpty(providerInfo.getIdCardValidDate(),null)){
                    provider.setSFZ_DQ(AdscmDateUtils.getDateFomat(providerInfo.getIdCardValidDate()));
                }
                String worker = "0";
                if (AdscmBaseUtils.getInstance().isNotEmpty(providerInfo.getCreateNurse(), null)) {
                    worker = providerInfo.getCreateNurse();
                }
                provider.setRegister(worker);
                //查询登记信息
                String registerNo = AdscmDateUtils.getNowOnlyDateFomat2(providerInfo.getCreateDate());
                Wrapper<ProviderReg> regWrapper = new EntityWrapper<>();
                regWrapper.eq("providerNo", providerInfo.getId());
                regWrapper.like("registerNo", registerNo, SqlLike.RIGHT);
                List<ProviderReg> providerRegs = providerRegMapper.selectList(regWrapper);
                if (providerRegs != null && providerRegs.size() > 0) {
                    ProviderReg providerReg = providerRegs.get(0);
                    provider.setSmallNo(providerReg.getRegisterNo());
                }
                //血型
                if ("1".equals(providerInfo.getBloodType())) {
                    provider.setBloodType("A");
                } else if ("2".equals(providerInfo.getBloodType())) {
                    provider.setBloodType("B");
                } else if ("3".equals(providerInfo.getBloodType())) {
                    provider.setBloodType("AB");
                } else if ("4".equals(providerInfo.getBloodType())) {
                    provider.setBloodType("O");
                }
                //同步建档，在登记时指纹打钩的
                provider.setFingerMark("1");
                // 同步指纹信息
                Wrapper<ProviderZw> providerZwWrapper = new EntityWrapper<>();
                providerZwWrapper.eq("providerNo", providerInfo.getId());
                List<ProviderZw> providerZws = providerZwMapper.selectList(providerZwWrapper);
                if (providerZws!=null){
                    for (ProviderZw providerZw : providerZws) {
                        List<TZwtable> tZwtables = tZwtableMapper.selectZw(providerInfo.getCardId(), providerZw.getCode());
                        TZwtable tZwtable = null;
                        if (tZwtables != null && tZwtables.size() > 0) {
                            tZwtable = tZwtables.get(0);
                        } else {
                            tZwtable = new TZwtable();
                        }

                        tZwtable.setCode(providerZw.getCode());
                        tZwtable.setProviderno(providerInfo.getCardId());
                        tZwtable.setZW(providerZw.getZw());

                        if (tZwtable.getID() != null && !"".equals(tZwtable.getID())) {
                            tZwtableMapper.updateZw(tZwtable);
                        } else {
                            tZwtableMapper.saveZw(tZwtable);
                        }
                        logger.info(
                                "同步的供浆者【" + providerInfo.getCardId() + "-" + providerInfo.getName() + "】指纹 【" + providerZw.getCode() + "】 结束~~~");
                    }
                }
                if (cardtable.getICNo() != null && !"".equals(cardtable.getICNo())) {
                    tCardtableMapper.updateCardTable(cardtable);
                }
                if (provider.getBaseNo() != null && !"".equals(provider.getBaseNo())) {
                    tProviderbaseinfoMapper.updateProviderBaseInfo(provider);
                } else {
                    tProviderbaseinfoMapper.addProviderBaseInfo(provider);
                }
                successGjz.add(providerInfo);
                logger.info("同步的供浆者【" + providerInfo.getCardId() + "-" + providerInfo.getName() + "】结束~~~");

            }catch (Exception e){
                e.printStackTrace();
                logger.info("同步的供浆者【" + providerInfo.getCardId() + "-" + providerInfo.getName() + "】异常，异常信息：" + e.getMessage());
            }
        }

        // 更新佳颖数据库中的同步时间
        for (ProviderInfo providerInfo : successGjz) {

            try {
                logger.info("更新浆员信息表 GJZXX 中的【" + providerInfo.getCardId() + "-" + providerInfo.getName() + "】的同步状态开始~~~");

                providerInfo.setSynDate(now);
                // 这里将同步时间修改为现在
                providerInfoMapper.updateById(providerInfo);
                logger.info("更新浆员信息表 GJZXX 中的【" + providerInfo.getCardId() + "-" + providerInfo.getName() + "】的同步状态结束~~~");
            } catch (Exception e) {
                e.printStackTrace();
                logger.info(
                        "更新浆员信息表 GJZXX 中的【" + providerInfo.getCardId() + "-" + providerInfo.getName()+ "】的同步状态异常，异常信息：" + e.getMessage());
            }
        }

    }

    @Override
    public void doProviderRegisterExec() throws Exception {
        Date now = new Date();
        Date nowZero = AdscmDateUtils.getFormateDate(now);
        String  zero= AdscmDateUtils.getDateFormat(now);
        //查询待同步的登记信息
        Wrapper<ProviderReg> regWrapper=new EntityWrapper<>();
        regWrapper.last("where  modifyTime>= synDate and modifyTime >="+zero);//同步当天记录 modifyTime>=zero
        List<ProviderReg> providerRegs = providerRegMapper.selectList(regWrapper);
        logger.info("待同步的供浆者登记信息 记录数=" + providerRegs.size());
        List<ProviderReg> successReg = new ArrayList<>();
        for (ProviderReg providerReg : providerRegs) {
            try {
                ProviderInfo providerInfo = providerInfoMapper.selectById(providerReg.getProviderNo());
                if (!AdscmBaseUtils.getInstance().isNotEmpty(providerInfo,null)){
                    logger.info("同步的供浆者【" + providerInfo.getCardId() + "】登记信息失败，没有找到供浆者基本信息 ~~~");
                    continue;
                }
                logger.info("同步的供浆者【" + providerInfo.getCardId() + "】登记信息开始~~~");
                //查询精英是否有登记信息了
                TProviderregister providerRegister = new TProviderregister();
                providerRegister.setSmallNo(providerReg.getRegisterNo());
                List<TProviderregister> providerregisterList = tProviderregisterMapper.getProviderRegister(providerRegister);
                if (providerregisterList!=null &&providerregisterList.size()>0){
                    providerRegister=providerregisterList.get(0);
                }else {
                    //未查询到数据
                    providerRegister.setIDNo(providerReg.getIdNo());
                    providerRegister.setProviderNo(providerInfo.getCardId());
                    providerRegister.setIsRegPass("1");
                    if (providerReg.getBodyCheckPass()){
                        providerRegister.setIsBodyPass("1");
                    }else {
                        providerRegister.setIsBodyPass("0");
                    }
                    providerRegister.setIsValidate("0");
                    providerRegister.setValidater("0");
                    if (providerReg.getAssayPass()){
                        providerRegister.setIsAssayPass("1");
                    }else {
                        providerRegister.setIsAssayPass("0");
                    }
                    providerRegister.setIsOrder("0");
                    providerRegister.setPromulgator("0");
                    providerRegister.setIsShout("0");
                    providerRegister.setShouter("0");
                    providerRegister.setIsCollection("0");
                    providerRegister.setIsRate("0");
                    providerRegister.setProviderType("1");
                    providerRegister.setRegistWorker(providerReg.getRegNurse());
                    providerRegister.setRegistDate(AdscmDateUtils.getDateFomat(providerReg.getRegTime()));
                    providerRegister.setRefuseDate("1970-01-01 08:00:00");
                    if (providerReg.getYq()){
                        providerRegister.setYyisvalidate("1");
                    }else {
                        providerRegister.setYyisvalidate("0");
                    }
                    providerRegister.setIsAuditing("1");
                    providerRegister.setAssessor("0");
                    providerRegister.setShoutdate("1970-01-01 08:00:00");
                    providerRegister.setOrg_id("0");
                    providerRegister.setUpdate_flag("2");
                    providerRegister.setUpdate_date("1970-01-01 08:00:00");
                    providerRegister.setWeb_flag("-1");
                    providerRegister.setIs_HD(null);
                    providerRegister.setOrg_id_SW("0");
                    providerRegister.setUpdate_flag_SW("2");
                    providerRegister.setUpdate_date_SW("1970-01-01 08:00:00");
                    providerRegister.setWeb_flag_SW("-1");
                    providerRegister.setOrg_id_QT("0");
                    providerRegister.setUpdate_flag_QT("2");
                    providerRegister.setUpdate_date_QT("1970-01-01 08:00:00");
                    providerRegister.setWeb_flag_QT("-1");
                    providerRegister.setXYH_SmallNo(providerReg.getSampleNo());
                    //查询费用信息
                    Wrapper<ProviderCost> providerCostWrapper =new EntityWrapper<>();
                    providerCostWrapper.eq("registerNo",providerReg.getRegisterNo());
                    List<ProviderCost> providerCosts = providerCostMapper.selectList(providerCostWrapper);
                    if (providerCosts!=null&& providerCosts.size()>0){
                        ProviderCost providerCost = providerCosts.get(0);
                        providerRegister.setTrafficFee(providerCost.getTrafficFee().toString());
                    }
                    //根据地址计算计算路程
                    String address = providerInfo.getAddress();
                    if (AdscmBaseUtils.getInstance().isNotEmpty(address,null)){
                        ProviderAddressAllowance providerAddressAllowance=null;
                        List<ProviderAddressAllowance> providerAddressAllowances = providerAddressAllowanceMapper.selectList(null);
                        for (ProviderAddressAllowance addressAllowance : providerAddressAllowances) {
                            if (address.indexOf(addressAllowance.getAddress()) >= 0) {
                                if (providerAddressAllowance == null) {
                                    providerAddressAllowance = addressAllowance;
                                } else if (addressAllowance.getAddress().length() > providerAddressAllowance.getAddress().length()) {
                                    providerAddressAllowance = addressAllowance;
                                }
                            }
                        }
                        if (AdscmBaseUtils.getInstance().isNotEmpty(providerAddressAllowance,null)){
                            providerRegister.setLucheng(providerAddressAllowance.getDistance().toString());
                        }else {
                            providerRegister.setLucheng("0");
                        }
                    }else {
                        providerRegister.setLucheng("0");
                    }

                    if (providerReg.getIfGdjy()){
                        providerRegister.setIF_GDJY("1");
                    }else {
                        providerRegister.setIF_GDJY("0");
                    }

                    providerRegister.setWXYYF("0");
                    providerRegister.setWXFF("0");
                    providerRegister.setBus_KM("0");
                    providerRegister.setCNMBLSYLRD("0");
                    providerRegister.setYMShang("0");
                    providerRegister.setYMXia("0");
                    providerRegister.setLSTJG("0");
                    providerRegister.setLSTWERKER("0");
                    providerRegister.setIfLST("0");
                    providerRegister.setIFZX("0");
                    providerRegister.setZxworker("0");
                    providerRegister.setNewrs("0");
                    providerRegister.setHHPHID("0");
                    providerRegister.setHHPHIDVIP("0");
                    providerRegister.setSFXS("1");
                    providerRegister.setDELBZ("0");
                    providerRegister.setJSRID("0");
                    providerRegister.setJSRifcl("0");
                    providerRegister.setDateBookingworker("0");
                    logger.info("同步的供浆者【" + providerInfo.getCardId() + "】新建登记信息 ~~~");
                }
                TRegisterteminfo temp = new TRegisterteminfo();
                temp.setSmallNo(providerReg.getRegisterNo());
                List<TRegisterteminfo> regTempList = tRegisterteminfoMapper.selectRegisterteminfo(temp);
                boolean flag = false;
                if (regTempList != null && regTempList.size() > 0) {
                    temp = regTempList.get(0);
                    flag = true;
                }

                temp.setProviderno(providerInfo.getCardId());
                temp.setRegistDate(AdscmDateUtils.getDateFomat(providerReg.getRegTime()));
                temp.setSmallNo(providerReg.getRegisterNo());

                providerRegister.setProviderNo(providerInfo.getCardId());
                if (AdscmBaseUtils.getInstance().isNotEmpty(providerRegister.getRegisterNo(),null)){
                    tProviderregisterMapper.updateProviderRegister(providerRegister);
                    logger.info("同步的供浆者【" + providerInfo.getCardId() + "】更新登记信息 ~~~");
                }else {
                    tProviderregisterMapper.addProviderRegister(providerRegister);
                    logger.info("同步的供浆者【" + providerInfo.getCardId() + "】新建登记信息成功 ~~~");
                }

                if (flag) {
                    tRegisterteminfoMapper.updateRegisterteminfo(temp);
                } else {
                    tRegisterteminfoMapper.saveRegisterteminfo(temp);
                }

                successReg.add(providerReg);
                //登记日志
                 String optionerName="";
                JyUser jyUser = jyUserMapper.selectById(providerReg.getRegNurse());
                if (AdscmBaseUtils.getInstance().isNotEmpty(jyUser,null)){
                    optionerName=jyUser.getName();
                }
                Systemlogjiaying sysLog=new Systemlogjiaying();
                sysLog.setModeName("供浆员登记");
                String optionInfo="操作员："+optionerName+"登记浆员编号为："+providerInfo.getCardId()+"小样号为："+providerReg.getRegisterNo()+" 登记成功！";
                sysLog.setOptioninfo(optionInfo);
                sysLog.setOptionter(providerReg.getRegNurse());
                sysLog.setOptionterdate(providerReg.getRegTime());
                Date setZeroTime = DateTools.getInstance().setZeroTime(providerReg.getRegTime());
                sysLog.setOptdate(setZeroTime);
                sysLog.setSynDate(DateTools.getInstance().setZeroTime(new Date()));
                sysLog.setModifyTime(new Date());
                sysLog.setDelbat("0");
                systemlogjiayingMapper.insert(sysLog);
                logger.info("供浆者登记日志【" + providerInfo.getCardId() + "】添加~~~");
                //固定浆员登记
                if (providerReg.getIfGdjy()){
                    Systemlogjiaying sysLog1=new Systemlogjiaying();
                    sysLog1.setModeName("固定浆员登记");
                    String optionInfo1="操作员："+optionerName+"把浆员："+providerInfo.getName()+"供浆员编号为："+providerInfo.getCardId()+" 进行扫描登记！";
                    sysLog1.setOptioninfo(optionInfo1);
                    sysLog1.setOptionter(providerReg.getRegNurse());
                    sysLog1.setOptionterdate(providerReg.getRegTime());
                    sysLog1.setOptdate(setZeroTime);
                    sysLog1.setSynDate(DateTools.getInstance().setZeroTime(new Date()));
                    sysLog1.setModifyTime(new Date());
                    sysLog1.setDelbat("0");
                    systemlogjiayingMapper.insert(sysLog1);
                    logger.info("登记固定浆员日志【" + providerInfo.getCardId() + "】添加~~~");
                }
                //新浆员登记
                if (providerInfo.getCardId().startsWith("R")){
                    Systemlogjiaying sysLog2=new Systemlogjiaying();
                    sysLog2.setModeName("新浆员登记");
                    String optionInfo2="操作员："+optionerName+"登记了一个新浆员："+providerInfo.getName()+"编号为："+providerInfo.getCardId()+"全小样号是："+providerReg.getRegisterNo();
                    sysLog2.setOptioninfo(optionInfo2);
                    sysLog2.setOptionter(providerReg.getRegNurse());
                    sysLog2.setOptionterdate(providerReg.getRegTime());
                    sysLog2.setOptdate(setZeroTime);
                    sysLog2.setSynDate(DateTools.getInstance().setZeroTime(new Date()));
                    sysLog2.setModifyTime(new Date());
                    sysLog2.setDelbat("1");
                    systemlogjiayingMapper.insert(sysLog2);
                    logger.info("登记新浆员日志【" + providerInfo.getCardId() + "】添加~~~");
                }
                logger.info("同步的供浆者【" + providerInfo.getCardId() + "】登记信息结束~~~");
            }catch (Exception e){
                logger.info("同步的供浆者【" +  providerReg.getRegisterNo() + "】登记信息异常，异常信息：" + e.getMessage());

            }
        }
        // 更新佳颖数据库中的同步时间
        for (ProviderReg providerReg : successReg) {
            try {
                logger.info("更新同步的供浆者【" + providerReg.getRegisterNo() + "】登记信息的同步状态开始~~~");
                providerReg.setSynDate(now);
                providerRegMapper.updateById(providerReg);
                logger.info("更新同步的供浆者【" +  providerReg.getRegisterNo()+ "】登记信息的同步状态结束~~~");
            } catch (Exception e) {
                e.printStackTrace();
                logger.info("更新供浆者【" +  providerReg.getRegisterNo() + "】登记信息的同步状态异常，异常信息：" + e.getMessage());
            }

        }
    }

    @Override
    public void doBodyCheckExec() throws Exception {
//        SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd");
        Date now = new Date();//df.parse("2008-02-11");
        String nowStr = DateTools.getInstance().dateFormat(now, "yyyy-MM-dd HH:mm:ss");

        BodyCheck gjzBodyCheck = new BodyCheck();
        gjzBodyCheck.setMODIFY_TIME(nowStr);
        List<BodyCheck> bodyCheckList = bodyCheckMapper.selectByBodyCheck(gjzBodyCheck);

        logger.info("待同步的供浆者体检信息 记录数=" + bodyCheckList.size());

        List<BodyCheck> successBodyCheck = new ArrayList<BodyCheck>();

        for (BodyCheck gbc : bodyCheckList) {

            try {
                logger.info("同步的供浆者【" + gbc.getProviderNo() + "】体检信息开始~~~");

                String bcDate = null;
                if (gbc.getRecodeEndTime() != null){
                    bcDate = DateTools.getInstance().dateFormatZero(gbc.getRecodeEndTime());
                }
                ProviderInfo gjz = new ProviderInfo();
                gjz.setId(Long.valueOf(gbc.getProviderNo()));
                List<ProviderInfo> gjzList = providerInfoMapper.getGJZXX(gjz);
                if (gjzList != null && gjzList.size() > 0) {
                    gjz = gjzList.get(0);
                } else {
                    logger.info("同步的供浆者【" + gbc.getProviderNo() + "】体检信息失败，没有找到供浆者基本信息 ~~~");
                    continue;
                }
//                DataSourceContextHolder.setDataSourceType(DataSourceConst.jingying);
                TProviderregister providerRegister = new TProviderregister();
                providerRegister.setSmallNo(gbc.getRegisterNo());
                List<TProviderregister> regList = tProviderbaseinfoMapper.getProviderRegister(providerRegister);
                if (regList != null && regList.size() > 0) {
                    providerRegister = regList.get(0);
                } else {
                    logger.info("同步的供浆者【" + gbc.getProviderNo() + "】体检信息失败，没有找到供浆者在精英的登记信息 ~~~");
                    continue;
                }

                TBodycheckrecord tbc = new TBodycheckrecord();
                tbc.setIDNo(gjz.getIdNo());
//                tbc.setBodyCheckDate(bcDate);
                tbc.setSmallNo(gbc.getRegisterNo());

                List<TBodycheckrecord> tbcList = tBodycheckrecordMapper.getBodyCheckRecord(tbc);

                if (tbcList != null && tbcList.size() > 0) {
                    tbc = tbcList.get(0);
                } else {
                    tbc.setIDNo(gjz.getIdNo());

                    tbc.setSmallNo(gbc.getRegisterNo());

                    if (gjz.getCardId().indexOf("R") >= 0) {
                        tbc.setIfx("1");
                    } else {
                        tbc.setIfx("0");
                    }
                    tbc.setTj_find("是");// 健康征询
                    tbc.setIF_GDJY(providerRegister.getIF_GDJY());// 是否固定奖员
                    tbc.setIsAuditing("0");
                    tbc.setAssessor("0");
                    tbc.setOrg_id("0");
                    tbc.setUpdate_flag("1");
                    tbc.setUpdate_date(DateTools.getInstance().dateFormat(new Date(0L), "yyyy-MM-dd HH:mm:ss"));
                    tbc.setWeb_flag("-1");
                    tbc.setOrg_id_SW("0");
                    tbc.setUpdate_flag_SW("1");
                    tbc.setUpdate_date_SW(DateTools.getInstance().dateFormat(new Date(0L), "yyyy-MM-dd HH:mm:ss"));
                    tbc.setWeb_flag_SW("-1");
                    tbc.setOrg_id_QT("0");
                    tbc.setUpdate_flag_QT("1");
                    tbc.setUpdate_date_QT(DateTools.getInstance().dateFormat(new Date(0L), "yyyy-MM-dd HH:mm:ss"));
                    tbc.setWeb_flag_QT("-1");
                }
                if (AdscmBaseUtils.getInstance().isNotEmpty(gbc.getRecodeEndTime(),null)){
                    tbc.setBodyCheckDate(DateTools.getInstance().dateFormatZero(gbc.getRecodeEndTime()));
                }
                tbc.setProviderNo(gjz.getCardId());
                tbc.setRegisterNo(providerRegister.getRegisterNo());

                int worker = 0;
//                if (NumberTools.getInstance().isNumeric2(gbc.getAssessor().substring(3))) {
//                    worker = Integer.parseInt(gbc.getAssessor().substring(3));
//                }
                if(AdscmBaseUtils.getInstance().isNotEmpty(gbc.getBodyCheckWorker(),null)){
                    tbc.setBodyCheckWorker(gbc.getBodyCheckWorker());// ID前三位必须是字母
                }else {
                    tbc.setBodyCheckWorker("0");// ID前三位必须是字母
                }
                tbc.setAvoirdupois(gbc.getWeight());
                tbc.setAnimalHeat(gbc.getAnimalHeat());
                tbc.setPulse(gbc.getPulse());
                if (AdscmBaseUtils.getInstance().isNotEmpty(gbc.getHighBlood(),null)){
                    tbc.setBloodPressure(gbc.getHighBlood() + "/" + gbc.getLowBlood());
                }

                tbc.setXB(gbc.getChest() == 1 ? "合格" : "不合格");
                tbc.setFB(gbc.getAbdomen() == 1 ? "合格" : "不合格");
                tbc.setPF(gbc.getSkin() == 1 ? "合格" : "不合格");
                tbc.setWG(gbc.getFacial() == 1 ? "合格" : "不合格");
                tbc.setSZ(gbc.getLimbs() == 1 ? "合格" : "不合格");

                tbc.setHeart("1");
                tbc.setLung("1");
                tbc.setLiver("1");
                tbc.setSpleen("1");

                // String result = "";
                if (gbc.getBodyCheckResult() != null && gbc.getBodyCheckResult() == 1) {
                    providerRegister.setIsBodyPass("1");
                    tbc.setBodyCheckResult("1");
                    // result = "合格";
                } else {
                    providerRegister.setIsBodyPass("0");
                    tbc.setBodyCheckResult("0");
                    // result = "不合格";
                }

                if (tbc.getBodyCheckNo() != null && !"".equals(tbc.getBodyCheckNo())) {
                    tBodycheckrecordMapper.updateBodyCheckRecord(tbc);
                } else {
                    tBodycheckrecordMapper.addBodyCheckRecord(tbc);
                }

                providerRegister.setIsOrder("1");// 让其状态到 采浆验证的 未验证人员队列中去
                tProviderregisterMapper.updateProviderRegister(providerRegister);

                successBodyCheck.add(gbc);
                //同步体检日志
                String  optionerName="";
                JyUser jyUser = jyUserMapper.selectById(gbc.getBodyCheckWorker());
                if (AdscmBaseUtils.getInstance().isNotEmpty(jyUser,null)){
                    optionerName=jyUser.getName();
                }
                String  result="";
                if (gbc.getBodyCheckResult() != null && gbc.getBodyCheckResult()==1){
                    result="合格";
                }else {
                    result="不合格";
                }
                Systemlogjiaying  sysLog=new Systemlogjiaying();
                if (gjz.getCardId().startsWith("R")){
                    sysLog.setModeName("新供浆员体检");
                    String optionInfo="操作员："+optionerName+"保存新浆员："+gjz.getName()+"并且供浆员编号为："+gjz.getCardId()+"的体检结果为："+result+"的信息！";
                    sysLog.setOptioninfo(optionInfo);
                    sysLog.setOptionter(gbc.getBodyCheckWorker());
                    if (AdscmBaseUtils.getInstance().isNotEmpty(gbc.getRecodeEndTime(),null)){
                        sysLog.setOptionterdate(AdscmDateUtils.parseDateL(gbc.getRecodeEndTime()));
                        Date setZeroTime = DateTools.getInstance().setZeroTime(AdscmDateUtils.parseDateL(gbc.getRecodeEndTime()));
                        sysLog.setOptdate(setZeroTime);
                    }
                    sysLog.setSynDate(DateTools.getInstance().setZeroTime(new Date()));
                    sysLog.setModifyTime(new Date());
                    sysLog.setDelbat("0");
                    systemlogjiayingMapper.insert(sysLog);
                    logger.info("新增的新浆员【" + gbc.getProviderNo() + "】体检日志信息成功~~~");
                }else {

                    sysLog.setModeName("供浆员体检记录");
                    String optionInfo="操作员："+optionerName+"保存老浆员："+gjz.getName()+"并且供浆员编号为："+gjz.getCardId()+"的体检"+result+"信息！";
                    sysLog.setOptioninfo(optionInfo);
                    sysLog.setOptionter(gbc.getBodyCheckWorker());
                    if(AdscmBaseUtils.getInstance().isNotEmpty(gbc.getRecodeEndTime(),null)){
                        sysLog.setOptionterdate( AdscmDateUtils.parseDateL(gbc.getRecodeEndTime()) );
                        Date setZeroTime = DateTools.getInstance().setZeroTime(AdscmDateUtils.parseDateL(gbc.getRecodeEndTime()));
                        sysLog.setOptdate(setZeroTime);
                    }
                    sysLog.setSynDate(DateTools.getInstance().setZeroTime(new Date()));
                    sysLog.setModifyTime(new Date());
                    sysLog.setDelbat("0");
                    systemlogjiayingMapper.insert(sysLog);
                    logger.info("新增的供浆者【" + gbc.getProviderNo() + "】体检日志信息成功~~~");
                }

                logger.info("同步的供浆者【" + gbc.getProviderNo() + "】体检信息结束~~~");
            } catch (Exception e) {
                e.printStackTrace();
                logger.info("同步的供浆者【" + gbc.getProviderNo() + "】体检信息异常：" + e.getMessage());
            }

        }
//        DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
        // 更新佳颖数据库中的同步状态
        for (BodyCheck gbc : successBodyCheck) {
            try {
                logger.info("更新浆员体检表 gjz_bodycheck 中的【" + gbc.getProviderNo() + "-" + gbc.getRegisterNo() + "】的同步状态开始~~~");

                // 这里将同步的状态改为已同步
                gbc.setSYNDATE(nowStr);
                bodyCheckMapper.updateById(gbc);
                logger.info("更新浆员体检表 gjz_bodycheck 中的【" + gbc.getProviderNo() + "-" + gbc.getRegisterNo() + "】的同步状态结束~~~");
            } catch (Exception e) {
                e.printStackTrace();
                logger.info("更新浆员体检表 gjz_bodycheck 中的【" + gbc.getProviderNo() + "-" + gbc.getRegisterNo() + "】的同步状态异常，异常信息："
                        + e.getMessage());
            }
        }

    }

    @Override
    public void doAllotExec() throws Exception {
        Date now = new Date();
        String nowZero = AdscmDateUtils.getDateFormat(now);
        String nowStr = DateTools.getInstance().dateFormat(now, "yyyy-MM-dd HH:mm:ss");
        String today = DateTools.getInstance().dateFormatZero(nowStr);

        //查询 待同步分配信息
        Wrapper<ProviderAllot> providerAllotWrapper =new EntityWrapper<>();
        providerAllotWrapper.last("where  modifyTime >= synDate  and modifyTime>="+nowZero);//查询当天同步信息
        List<ProviderAllot> providerAllots = providerAllotMapper.selectList(providerAllotWrapper);
        logger.info("待同步的供浆者分配信息 记录数=" + providerAllots.size());
        List<ProviderAllot> successAllt = new ArrayList<>();
        for (ProviderAllot providerAllot : providerAllots) {
            try {
                //查询浆员基本信息
                logger.info("同步的供浆者【"+providerAllot.getProviderNo() +":"+ providerAllot.getRegisterNo() + "】分配信息开始~~~");
                ProviderInfo providerInfo = providerInfoMapper.selectById(providerAllot.getProviderNo());

                if (AdscmBaseUtils.getInstance().isNotEmpty(providerInfo,null)) {
                } else {
                    logger.info("同步的供浆者【" + providerAllot.getProviderNo() +":"+ providerAllot.getRegisterNo() + "】分配信息失败，没有找到供浆者基本信息 ~~~");
                    continue;
                }
                //查询登记信息
                TProviderregister providerRegister = new TProviderregister();
                providerRegister.setSmallNo(providerAllot.getRegisterNo());
                List<TProviderregister> regList = tProviderregisterMapper.getProviderRegister(providerRegister);
                if (regList != null && regList.size() > 0) {
                    providerRegister = regList.get(0);
                } else {
                    logger.info("同步的供浆者【" +providerAllot.getProviderNo() +":"+ providerAllot.getRegisterNo() + "】分配信息失败，没有找到供浆者在精英的登记信息 ~~~");
                    continue;
                }


                TCollectionrecord cRecord = new TCollectionrecord();
                cRecord.setProviderNo(providerInfo.getCardId());
                cRecord.setCollectionDate(today);
                // 回写待采浆信息
                List<TCollectionrecord> tcs = tCollectionrecordMapper.getCollectionRecord(cRecord);
                if (tcs != null && tcs.size() > 0) {
                    cRecord = tcs.get(0);
                    successAllt.add(providerAllot);
                } else {
                    cRecord.setCollectionDate(today);
                    cRecord.setIsCollection("0");
                    cRecord.setCollectionWorker("0");// 护士ID
                    cRecord.setPlasmaGross("0");
                    cRecord.setMachineStatus("1");
                    cRecord.setCollectionInstance("0");// 采浆量是否足够
                    cRecord.setCollectionResult("0");
                    cRecord.setIsAuditing("1");
                    cRecord.setRemark("");
                    cRecord.setIsAuditing("0");
                    cRecord.setAssessor("0");
                    cRecord.setAssayNo("0");

                    String d = DateTools.getInstance().dateFormat(new Date(0L), "yyyy-MM-dd");
                    cRecord.setOrg_id("0");
                    cRecord.setUpdate_flag("2");
                    cRecord.setUpdate_date(d);
                    cRecord.setWeb_flag("-1");

                    cRecord.setOrg_id_SW("0");
                    cRecord.setUpdate_flag_SW("2");
                    cRecord.setUpdate_date_SW(d);
                    cRecord.setWeb_flag_SW("-1");

                    cRecord.setOrg_id_QT("0");
                    cRecord.setUpdate_flag_QT("2");
                    cRecord.setUpdate_date_QT(d);
                    cRecord.setWeb_flag_QT("-1");

                    cRecord.setIDNo(providerInfo.getIdNo());
                    cRecord.setProviderNo(providerInfo.getCardId());
                    cRecord.setSmallNo(providerRegister.getSmallNo());
                    cRecord.setCollectiondate_info(nowStr);

                    cRecord.setIF_GDJY(providerRegister.getIF_GDJY());

                    // 修改精英登记信息
                    providerRegister.setIsShout("1");
                    int shouter = 0;
                    if (AdscmBaseUtils.getInstance().isNotEmpty(providerAllot.getCreator(),null)) {
                        try {
                            shouter = Integer.parseInt(providerAllot.getCreator());
                        } catch (Exception e) {
                        }
                    }
                    providerRegister.setShouter(shouter + "");
                    providerRegister.setShoutdate(today);
                    // 血清电泳
                    Wrapper<ProviderXqdyqd> providerXqdyqdWrapper =new EntityWrapper<>();
                    providerXqdyqdWrapper.eq("providerNo",providerAllot.getProviderNo());
                    providerXqdyqdWrapper.eq("registerNo",providerAllot.getRegisterNo());
                    List<ProviderXqdyqd> providerXqdyqds = providerXqdyqdMapper.selectList(providerXqdyqdWrapper);
                    if (providerXqdyqds!=null &&providerXqdyqds.size()>0){
                        ProviderXqdyqd providerXqdyqd = providerXqdyqds.get(0);
                        TAssayXqdy jinyinxqdy = new TAssayXqdy();
                        jinyinxqdy.setProviderNo(providerInfo.getCardId());
                        jinyinxqdy.setSmallno(providerRegister.getSmallNo());
                        List<TAssayXqdy> assayXQDY = tAssayXqdyMapper.getAssayXQDY(jinyinxqdy);
                        if (assayXQDY != null && assayXQDY.size() > 0) {

                        } else {
                            String nullDate = DateTools.getInstance().dateFormatZero("1900-01-01 00:00:00");

                            jinyinxqdy.setProviderNo(providerInfo.getCardId());
                            jinyinxqdy.setSmallno(providerRegister.getSmallNo());

                            jinyinxqdy.setXQDYPH("302D" + providerXqdyqd.getId());
                            jinyinxqdy.setXQDYXH("" + providerXqdyqd.getCidx());
                            jinyinxqdy.setLastXQDYdate(today);

                            jinyinxqdy.setOrg_id("0");
                            jinyinxqdy.setUpdate_flag("1");
                            jinyinxqdy.setUpdate_date(nullDate);
                            jinyinxqdy.setWeb_flag("-1");
                            jinyinxqdy.setOrg_id_SW("0");
                            jinyinxqdy.setUpdate_flag_SW("1");
                            jinyinxqdy.setUpdate_date_SW(nullDate);
                            jinyinxqdy.setWeb_flag_SW("-1");
                            jinyinxqdy.setOrg_id_QT("0");
                            jinyinxqdy.setUpdate_flag_QT("1");
                            jinyinxqdy.setUpdate_date_QT(nullDate);
                            jinyinxqdy.setWeb_flag_QT("-1");

                            jinyinxqdy.setLastXQDYAssayer(null);
                            jinyinxqdy.setBDB(null);
                            jinyinxqdy.setTuPu(null);
                            jinyinxqdy.setDYDW(null);
                            jinyinxqdy.setDYBZ(null);
                            jinyinxqdy.setCZSJ(today);

                            tAssayXqdyMapper.addAssayXQDY(jinyinxqdy);
                        }

                    }
                    if (cRecord.getCollectionNo() != null && !"".equals(cRecord.getCollectionNo())) {
                        tCollectionrecordMapper.updateCollectionRecord(cRecord);
                    } else {
                        tCollectionrecordMapper.addCollectionRecord(cRecord);
                    }
                    tProviderregisterMapper.updateProviderRegister(providerRegister);
                    successAllt.add(providerAllot);
                    //分配日志
                    JyUser jyUser = jyUserMapper.selectById(providerAllot.getCreator());
                    String  optionerName="";
                    if (AdscmBaseUtils.getInstance().isNotEmpty(jyUser,null)){
                        optionerName=jyUser.getName();
                    }

                    Systemlogjiaying  systemlogjiaying=new Systemlogjiaying();
                    systemlogjiaying.setModeName("采浆喊号");
                    systemlogjiaying.setOptioninfo("操作员："+optionerName+"把供浆员："+providerInfo.getName()+"，编号为："+providerInfo.getCardId()+"全登记号为："+providerAllot.getRegisterNo()+" 已喊号！");
                    systemlogjiaying.setOptionter(providerAllot.getCreator());
                    systemlogjiaying.setOptionterdate(providerAllot.getAllotDate());
                    systemlogjiaying.setOptdate(AdscmDateUtils.getFormateDate(providerAllot.getAllotDate()));
                    systemlogjiaying.setSynDate(AdscmDateUtils.getFormateDate(new Date()));
                    systemlogjiaying.setModifyTime(new Date());

                    systemlogjiaying.setDelbat("0");
                    systemlogjiayingMapper.insert(systemlogjiaying);
                    logger.info("新增的供浆者【" + providerAllot.getProviderNo() +":"+ providerAllot.getRegisterNo() + "】分配日志信息~~~");


                    logger.info("同步的供浆者【" + providerAllot.getProviderNo() +":"+ providerAllot.getRegisterNo() + "】分配信息结束~~~");
                }
            }catch (Exception e){
                e.printStackTrace();
                logger.info("同步的供浆者【" + providerAllot.getProviderNo() +":"+ providerAllot.getRegisterNo()+ "】分配信息异常：" + e.getMessage());
            }
        }
        for (ProviderAllot providerAllot : successAllt) {

            try {
                logger.info("更新浆员分配表  中的【" +  providerAllot.getProviderNo() +":"+ providerAllot.getRegisterNo() + "】的同步状态开始~~~");

                providerAllot.setSynDate(now);
                providerAllotMapper.updateById(providerAllot);
                logger.info("更新浆员分配表 中的【" +  providerAllot.getProviderNo() +":"+ providerAllot.getRegisterNo() + "】的同步状态结束~~~");
            } catch (Exception e) {
                e.printStackTrace();
                logger.info("更新浆员分配表 中的【" +  providerAllot.getProviderNo() +":"+ providerAllot.getRegisterNo() + "】的同步状态异常，异常信息："
                        + e.getMessage());
            }

        }
    }

    @Override
    public void doSampleCollectionExec() throws Exception {
        Date now = new Date();
        SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        String nowStr = DateTools.getInstance().dateFormat(dateFormat.parse("2016-11-20 00:00:00"), "yyyy-MM-dd HH:mm:ss");
        String nowStr = AdscmDateUtils.getDateFomat(now);
        String nowZero = DateTools.getInstance().dateFormatZero(nowStr);
        PlasmaSamples gSample = new PlasmaSamples();
        gSample.setMODIFY_TIME(nowStr);
        gSample.setRecodeStatus(0);//未处理的
//        DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
        List<PlasmaSamples> scList = plasmaSamplesMapper.selectBySample(gSample);

        List<PlasmaSamples> successSample = new ArrayList<PlasmaSamples>();

        logger.info("待同步的供浆小样采集 记录数=" + scList.size());

        for (PlasmaSamples gsc : scList) {
            try {
                logger.info("同步小样采集信息【" + gsc.getName() + "-" + gsc.getRegisterNo() + "】开始~~~");
                ProviderInfo gjz = new ProviderInfo();
                gjz.setId(Long.valueOf(gsc.getProviderNo()));
                List<ProviderInfo> gjzList = providerInfoMapper.getGJZXX(gjz);
                if (gjzList != null && gjzList.size() > 0) {
                    gjz = gjzList.get(0);
                } else {
                    logger.info("同步的供浆者【" + gsc.getProviderNo() + "】小样采集信息失败，没有找到供浆者基本信息 ~~~");
                    continue;
                }
                TProviderregister providerRegister = new TProviderregister();
                Date recordTime = gsc.getRecodeTime();
                if (recordTime != null){
                    String regDate = AdscmDateUtils.getNowOnlyDateFomat1(recordTime);
                    providerRegister.setRegistDate(regDate);
                    providerRegister.setIDNo(gjz.getIdNo());
                    List<TProviderregister> regList = tProviderregisterMapper.getProviderRegister(providerRegister);
                    if (regList != null && regList.size() > 0) {
                        providerRegister = regList.get(0);
                    } else {
                        logger.info("同步的供浆者【" + gsc.getProviderNo() + "】小样采集信息失败，没有找到供浆者在精英的登记信息 ~~~");
                        continue;
                    }
                }else{
                    logger.info("同步的供浆者【" + gsc.getProviderNo() + "】小样采集信息失败，没有日期 ~~~");
                    continue;
                }



                TAssayrecord tr = new TAssayrecord();
                tr.setIDNo(gjz.getIdNo());
                tr.setXYH_SmallNo(gsc.getSampleNo());

                List<TAssayrecord> trs = tAssayrecordMapper.getAssayRecord(tr);

                if (trs != null && trs.size() > 0) {
                    tr = trs.get(0);
                } else {

                    logger.info("新建小样采集信息");
                    tr.setBodyCheckNo("0");
                    tr.setIDNo(gsc.getIdNo());
                    tr.setProviderNo(gjz.getCardId());

                    tr.setSmallNo(providerRegister.getSmallNo());// 登记号
                    tr.setAssayWorker("0");
                    tr.setIsRepeat("0");
                    tr.setTempletNo("0");
                    tr.setAssayResult("0");
                    tr.setIsAuditing("0");
                    tr.setAssessor("0");
                    tr.setOrg_id("0");
                    tr.setUpdate_flag("1");
                    tr.setUpdate_date(DateTools.getInstance().dateFormat(new Date(0L), "yyyy-MM-dd HH:mm:ss"));
                    tr.setUpdate_flag("-1");
                    tr.setOrg_id_SW("0");
                    tr.setUpdate_flag_SW("2");
                    tr.setUpdate_date_SW(DateTools.getInstance().dateFormat(new Date(0L), "yyyy-MM-dd HH:mm:ss"));
                    tr.setWeb_flag_SW("-1");
                    tr.setOrg_id_QT("0");
                    tr.setUpdate_flag_QT("2");
                    tr.setUpdate_date_QT(DateTools.getInstance().dateFormat(new Date(0L), "yyyy-MM-dd HH:mm:ss"));
                    tr.setWeb_flag_QT("-1");

                    tr.setIF_GDJY("0");
                    tr.setIfLST("1");
                    if (gjz.getCardId().startsWith("R")) {
                        tr.setIfx("1");
                    } else {
                        tr.setIfx("0");
                    }
                }

                tr.setXYH_SmallNo(gsc.getSampleNo());// 小样号
                tr.setAssayDate(dateFormat.format(gsc.getRecodeTime()));
//                int worker = 30;
//                String nurseid = gsc.getCreateNurse();
//                if (nurseid != null && !"".equals(nurseid) && nurseid.length() > 3) {
//                    if (NumberTools.getInstance().isNumeric2(nurseid.substring(3))) {
//                        worker = Integer.parseInt(nurseid.substring(3));
//                    }
//                }
                tr.setLSTWERKER(gsc.getCreateNurse());
                tr.setAssayBBDate(dateFormat.format(gsc.getRecodeTime()));
                tr.setLSTdate(dateFormat.format(gsc.getRecodeTime()));

                // 写入assayRecordRegister表的数据
                TAssayrecordregister trr = new TAssayrecordregister();
                trr.setProviderno(gjz.getCardId());
                trr.setxYH_SmallNo(gsc.getSampleNo());

                List<TAssayrecordregister> trrs = tAssayrecordregisterMapper.getAssayRecordRegister(trr);

                boolean flag = false;
                if (trrs != null && trrs.size() > 0) {
                    trr = trrs.get(0);
                    flag = true;
                }

                trr.setAssayDate(dateFormat.format(gsc.getRecodeTime()));
                trr.setProviderno(gjz.getCardId());
                trr.setSmallno(tr.getSmallNo());
                trr.setxYH_SmallNo(tr.getXYH_SmallNo());

                // 回写登记信息
                providerRegister.setIsValidate("1");
                providerRegister.setValidater(gsc.getCreateNurse());
                providerRegister.setXYH_SmallNo(tr.getXYH_SmallNo());
                providerRegister.setYyisvalidate("1");
                tProviderregisterMapper.updateProviderRegister(providerRegister);

                if (flag) {
                    tAssayrecordregisterMapper.updateAssayRecordRegister(trr);
                } else {
                    tAssayrecordregisterMapper.addAssayRecordRegister(trr);
                }

                if (tr.getAssayNo() != null && !"".equals(tr.getAssayNo())) {
                    tAssayrecordMapper.updateAssayRecord(tr);
                } else {
                    tAssayrecordMapper.addAssayRecord(tr);
                }

                successSample.add(gsc);
                //同步小样信息
                if (gsc.getSampleType()==1){
                    String optionerName="";
                    JyUser jyUser = jyUserMapper.selectById(gsc.getCreateNurse());
                    if (AdscmBaseUtils.getInstance().isNotEmpty(jyUser,null)){
                        optionerName=jyUser.getName();
                    }
                    Systemlogjiaying  sysLog=new Systemlogjiaying();
                    sysLog.setModeName("小样室验证");
                    String optionInfo="操作员："+optionerName+" 把浆员："+gjz.getName()+"供浆员编号为："+gjz.getCardId()+"进行抽小样！";
                    sysLog.setOptioninfo(optionInfo);
                    sysLog.setOptionter(gsc.getCreateNurse());
                    sysLog.setOptionterdate(gsc.getGatheringTime());
                    Date setZeroTime = DateTools.getInstance().setZeroTime(gsc.getGatheringTime());
                    sysLog.setOptdate(setZeroTime);
                    sysLog.setSynDate(DateTools.getInstance().setZeroTime(new Date()));
                    sysLog.setModifyTime(new Date());
                    sysLog.setDelbat("0");
                    systemlogjiayingMapper.insert(sysLog);
                    logger.info("小样采集日志【" + gsc.getName() + "-" + gsc.getSampleNo() + "】添加~~~");
                }


                logger.info("同步小样采集信息【" + gsc.getName() + "-" + gsc.getSampleNo() + "】结束~~~");
            } catch (Exception e) {
                e.printStackTrace();
                logger.info("同步小样采集信息【" + gsc.getName() + "-" + gsc.getSampleNo() + "】异常，异常信息：" + e.getMessage());
            }

        }
        for (PlasmaSamples gsc : successSample) {
            try {
                logger.info(
                        "更新小样采集信息表 GJZ_SAMPLE_COLLECTION 中的【" + gsc.getName() + "-" + gsc.getName() + "】的同步状态开始~~~");

                gsc.setSYNDATE(nowStr);
                plasmaSamplesMapper.updateById(gsc);
                logger.info(
                        "更新小样采集信息表 GJZ_SAMPLE_COLLECTION 中的【" + gsc.getName() + "-" + gsc.getSampleNo() + "】的同步状态结束~~~");
            } catch (Exception e) {
                e.printStackTrace();
                logger.info("更新小样采集信息表 GJZ_SAMPLE_COLLECTION 中的【" + gsc.getName() + "-" + gsc.getSampleNo()
                        + "】的同步状态异常，异常信息：" + e.getMessage());
            }
        }

    }

    @Override
    public void doAssayExec() throws Exception {
        Date now = new Date();
        SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        String nowStr = DateTools.getInstance().dateFormat(dateFormat.parse("2016-11-20 00:00:00"), "yyyy-MM-dd HH:mm:ss");
        String nowStr = AdscmDateUtils.getDateFomat(now);
        PlasmaSamples assay = new PlasmaSamples();
        assay.setMODIFY_TIME(nowStr);
        assay.setRecodeStatus(1);//已处理的
        List<PlasmaSamples> aList = plasmaSamplesMapper.selectBySample(assay);

        List<PlasmaSamples> successAssay = new ArrayList<PlasmaSamples>();

        logger.info("待同步的供浆化检 记录数=" + aList.size());

        for (PlasmaSamples gsc : aList) {
            try {
                logger.info("同步化检信息【" + gsc.getProviderNo() + "-" + gsc.getSampleNo() + "】开始~~~");
                ProviderInfo gjz = new ProviderInfo();
                gjz.setId(Long.valueOf(gsc.getProviderNo()));
                List<ProviderInfo> gjzList = providerInfoMapper.getGJZXX(gjz);
                if (gjzList != null && gjzList.size() > 0) {
                    gjz = gjzList.get(0);
                } else {
                    logger.info("同步的供浆者【" + gsc.getProviderNo() + "】化检信息失败，没有找到供浆者基本信息 ~~~");
                    continue;
                }

//                String jlkssj = dateFormat.format(gsc.getRecodeEndTime());
//                jlkssj = DateTools.getInstance().dateFormatZero(jlkssj);
                TProviderregister providerRegister = new TProviderregister();
//                providerRegister.setRegistDate(jlkssj);
                providerRegister.setSmallNo(gsc.getRegisterNo());
                providerRegister.setIDNo(gjz.getIdNo());
                List<TProviderregister> regList = tProviderregisterMapper.getProviderRegister(providerRegister);
                if (regList != null && regList.size() > 0) {
                    providerRegister = regList.get(0);
                } else {
                    logger.info("同步的供浆者【" + gsc.getProviderNo() + "】化检信息失败，没有找到供浆者在精英的登记信息 ~~~");
                    continue;
                }

                TAssayrecord tr = new TAssayrecord();
                tr.setIDNo(gjz.getIdNo());
                tr.setXYH_SmallNo(gsc.getSampleNo());

                List<TAssayrecord> trs = tAssayrecordMapper.getAssayRecord(tr);

                if (trs != null && trs.size() > 0) {
                    tr = trs.get(0);
                } else {
                    tr.setIDNo(gjz.getIdNo());

                    tr.setSmallNo(providerRegister.getSmallNo());// 登记号
                    tr.setAssayWorker("0");
                    tr.setIsRepeat("0");
                    tr.setTempletNo("0");
                    tr.setAssayResult("0");
                    tr.setIsAuditing("0");
                    tr.setAssessor("0");
                    tr.setOrg_id("0");
                    tr.setUpdate_flag("1");
                    tr.setUpdate_date(DateTools.getInstance().dateFormat(new Date(0L), "yyyy-MM-dd HH:mm:ss"));
                    tr.setUpdate_flag("-1");
                    tr.setOrg_id_SW("0");
                    tr.setUpdate_flag_SW("2");
                    tr.setUpdate_date_SW(DateTools.getInstance().dateFormat(new Date(0L), "yyyy-MM-dd HH:mm:ss"));
                    tr.setWeb_flag_SW("-1");
                    tr.setOrg_id_QT("0");
                    tr.setUpdate_flag_QT("2");
                    tr.setUpdate_date_QT(DateTools.getInstance().dateFormat(new Date(0L), "yyyy-MM-dd HH:mm:ss"));
                    tr.setWeb_flag_QT("-1");
                    tr.setBodyCheckNo("0");

                    tr.setIF_GDJY(providerRegister.getIF_GDJY());
                    tr.setIfLST(providerRegister.getIfLST());
                    if (gjz.getCardId().startsWith("R")) {
                        tr.setIfx("1");
                    } else {
                        tr.setIfx("0");
                    }
                }

                tr.setXYH_SmallNo(gsc.getSampleNo());

//                int worker = 0;
//                String nurseid = gsc.getInspectionRecodePerson();
//                if (nurseid != null && !"".equals(nurseid) && nurseid.length() > 3) {
//                    if (NumberTools.getInstance().isNumeric2(nurseid.substring(3))) {
//                        worker = Integer.parseInt(nurseid.substring(3));
//                    }
//                }
                tr.setAssayWorker(gsc.getCreateNurse());

                tr.setProviderNo(gjz.getCardId());
                if("1".equals(gsc.getHBsAg())){
                    tr.setHBsAg("0");
                }else {
                    tr.setHBsAg("1");
                }
                if("1".equals(gsc.getHcv())){
                    tr.setHCV("0");
                }else {
                    tr.setHCV("1");
                }

                String alt = gsc.getALt() + "";
                if ("1".equals(alt)) {
                    alt = "≤40u";
                } else if ("2".equals(alt)) {
                    alt = ">40u";
                } else if ("3".equals(alt)) {
                    alt = "复检";
                } else if ("4".equals(alt)) {
                    alt = "≤25u";
                } else if ("5".equals(alt)) {
                    alt = ">25u";
                }
                tr.setALT(alt);

                if("1".equals(gsc.getHiv())){
                    tr.setHIV("0");
                }else {
                    tr.setHIV("1");
                }
                int xhdbhl = Integer.valueOf(gsc.getHemoglobinLevel());

                if (xhdbhl == 0) {
                    xhdbhl = -1;
                }

                // 液面上/下
                if (1 == xhdbhl) {
                    tr.setYMXia("1");
                    tr.setLSTJG("≥120");
                } else if (3 == xhdbhl) {
                    tr.setYMXia("1");
                    tr.setLSTJG("≥110");
                } else if (2 == xhdbhl) {
                    tr.setYMShang("1");
                    tr.setLSTJG("<120");
                } else if (4 == xhdbhl) {
                    tr.setYMShang("1");
                    tr.setLSTJG("<110");
                }

                String proteide = null;
                if (gsc.getProteinLevel() != null && !"".equals(gsc.getProteinLevel())) {
                    proteide = gsc.getProteinLevel();
                } else {
                    proteide = gsc.getHemoglobinLevel() + "";
                }
                if (proteide != null && !"".equals(proteide)) {
                    tr.setProteide(proteide);
                    if(proteide.length()>1){
                        tr.setZSYKDZ(proteide.substring(0, 1) + "." + proteide.substring(1, 2));
                    }
                }
                tr.setTempletNovar("检验");

                Integer hjjg = gsc.getInspectionResult();
                if (hjjg != null && 1 == hjjg) {
                    tr.setDBZJG("合格");
                }

                tr.setLSTWERKER(gsc.getCreateNurse());

                if (Integer.valueOf(gsc.getWholeBloodLevel()) == 0) {
                    tr.setAllBlood("1");
                } else if (Integer.valueOf(gsc.getWholeBloodLevel()) == 1) {
                    tr.setAllBlood("0");
                }
                if("1".equals(gsc.getSyphilis())){
                    tr.setSyphilis("0");
                }else {
                    tr.setSyphilis("1");
                }
                // String hjjg_ = "";
                if (gsc.getInspectionResult() == 1) {
                    // hjjg_ = "合格";
                    tr.setAssayResult("1");
                    providerRegister.setIsAssayPass("1");
                } else {
                    // hjjg_ = "不合格";
                    tr.setAssayResult("0");
                    providerRegister.setIsAssayPass("0");
                }
                // 修改精英化检记录
                providerRegister.setLSTWERKER(gsc.getCreateNurse());
                providerRegister.setXYH_SmallNo(gsc.getSampleNo());
                providerRegister.setLSTWERKER(gsc.getCreateNurse());

                String date = gsc.getSampleNo().substring(0, 8);// 小样化检的时间
                String date2 = DateTools.getInstance().dateFormatZero(date);
                tr.setAssayDate(date2);
                tr.setLSTdate(date2);
                tr.setAssayBBDate( AdscmDateUtils.getDateFomat(gsc.getRecodeTime()) );

                // 写入assayRecordRegister表的数据
                TAssayrecordregister trr = new TAssayrecordregister();
//				trr.setProviderno(gjz.getCARDID());
                trr.setxYH_SmallNo(gsc.getSampleNo());

                List<TAssayrecordregister> trrs = tAssayrecordregisterMapper.getAssayRecordRegister(trr);

                boolean flag = false;
                if (trrs != null && trrs.size() > 0) {
                    trr = trrs.get(0);
                    flag = true;
                }

                trr.setAssayDate(date2);
                trr.setProviderno(gjz.getCardId());
                trr.setSmallno(tr.getSmallNo());
                trr.setxYH_SmallNo(tr.getXYH_SmallNo());

                if (flag) {
                    tAssayrecordregisterMapper.updateAssayRecordRegister(trr);
                } else {
                    tAssayrecordregisterMapper.addAssayRecordRegister(trr);
                }

                tProviderregisterMapper.updateProviderRegister(providerRegister);
                if (tr.getAssayNo() != null && !"".equals(tr.getAssayNo())) {
                    tAssayrecordMapper.updateAssayRecord(tr);
                } else {
                    tAssayrecordMapper.addAssayRecord(tr);
                }

                successAssay.add(gsc);
                //日志同步蛋白检测

                String  optionerName="";
                JyUser jyUser = jyUserMapper.selectById(gsc.getInspectionRecodePerson());
                if (AdscmBaseUtils.getInstance().isNotEmpty(jyUser,null)) {
                    optionerName=jyUser.getName();
                }
                Systemlogjiaying  sysLog=new Systemlogjiaying();
                sysLog.setModeName("蛋白含量检测");

                String time = new SimpleDateFormat("yyyy-MM-dd").format(gsc);
                String proteinDetectionNo=  proteide.substring(0, 1)+"."+proteide.substring(1, 2);

                String optionInfo=time+"浆员编号为: "+gjz.getCardId()+"蛋白含量检测结果为: 折射仪刻度值："+proteinDetectionNo+"蛋白值："+proteide+"结果判定："+ tr.getDBZJG();
                sysLog.setOptioninfo(optionInfo);
                sysLog.setOptionter(gsc.getInspectionRecodePerson());
                sysLog.setOptionterdate(gsc.getRecodeEndTime());
                Date setZeroTime = DateTools.getInstance().setZeroTime(gsc.getRecodeEndTime());
                sysLog.setOptdate(setZeroTime);
                sysLog.setSynDate(DateTools.getInstance().setZeroTime(new Date()));
                sysLog.setModifyTime(new Date());
                sysLog.setDelbat("0");
                systemlogjiayingMapper.insert(sysLog);
                logger.info("新增化检日志【" + gsc.getCardId() + "-" + gsc.getSampleNo() + "】");
                  String  result="";
                 if (gsc.getInspectionResult()==1){
                     result="合格";
                 }else {
                     result="不合格";
                 }
                if (gjz.getCardId().startsWith("R")){
                    Systemlogjiaying  sysLog2=new Systemlogjiaying();
                    sysLog2.setModeName("新卡化验");
                    String optionInfo2="操作员："+optionerName+" 把浆员："+gjz.getName()+"临时编号为："+gjz.getCardId()+"的化验成："+result+"信息！";
                    sysLog2.setOptioninfo(optionInfo2);
                    sysLog2.setOptionter(gsc.getInspectionRecodePerson());
                    sysLog2.setOptionterdate(gsc.getRecodeEndTime());
                    sysLog2.setOptdate(setZeroTime);
                    sysLog2.setSynDate(DateTools.getInstance().setZeroTime(new Date()));
                    sysLog2.setModifyTime(new Date());
                    sysLog2.setDelbat("0");
                    systemlogjiayingMapper.insert(sysLog2);
                    logger.info("新增新浆员化检合格日志【" + gsc.getCardId() + "-" + gsc.getSampleNo() + "】");
                }else {
                    Systemlogjiaying  sysLog1=new Systemlogjiaying();
                    sysLog1.setModeName("供浆员化验记录");
                    String optionInfo1="操作员："+optionerName+"把浆员："+gjz.getName()+"编号为："+gjz.getCardId()+"的化验成："+result+"信息！";
                    sysLog1.setOptioninfo(optionInfo1);
                    sysLog1.setOptionter(gsc.getInspectionRecodePerson());
                    sysLog1.setOptionterdate(gsc.getRecodeEndTime());
                    sysLog1.setOptdate(setZeroTime);
                    sysLog1.setSynDate(DateTools.getInstance().setZeroTime(new Date()));
                    sysLog1.setModifyTime(new Date());
                    sysLog1.setDelbat("0");
                    systemlogjiayingMapper.insert(sysLog1);
                    logger.info("新增化检合格日志【" + gsc.getCardId() + "-" + gsc.getSampleNo() + "】");

                }
                //血红蛋白含量检测
                String hemoglobinDetectionResult=tr.getLSTJG();
                Systemlogjiaying  sysLog3=new Systemlogjiaying();
                sysLog3.setModeName("血红蛋白含量检测");
                String optionInfo3=time+"血红蛋白含量检测,检测结果为: 液面下判定结果"+hemoglobinDetectionResult+"g/L浆员编号为: "+gjz.getCardId();
                sysLog3.setOptioninfo(optionInfo3);
                sysLog3.setOptionter(gsc.getInspectionRecodePerson());
                sysLog3.setOptionterdate(gsc.getRecodeEndTime());
                sysLog3.setOptdate(setZeroTime);
                sysLog3.setSynDate(DateTools.getInstance().setZeroTime(new Date()));
                sysLog3.setModifyTime(new Date());
                sysLog3.setDelbat("0");
                systemlogjiayingMapper.insert(sysLog3);
                logger.info("新增血红蛋白含量检测【" + gsc.getCardId() + "-" + gsc.getSampleNo() + "】");



                logger.info("同步化检信息【" + gsc.getCardId() + "-" + gsc.getSampleNo() + "】结束~~~");
            } catch (Exception e) {
                e.printStackTrace();
                logger.info("同步化检信息【" + gsc.getCardId() + "-" + gsc.getCardId() + "】异常，异常信息：" + e.getMessage());
            }

        }
        for (PlasmaSamples gsc : successAssay) {
            try {
                logger.info(
                        "更新化检信息表 GJZ_SAMPLE_COLLECTION 中的【" + gsc.getCardId() + "-" + gsc.getSampleNo() + "】的同步状态开始~~~");

                gsc.setSYNDATE(nowStr);
                plasmaSamplesMapper.updateById(gsc);
                logger.info(
                        "更新化检信息表 GJZ_SAMPLE_COLLECTION 中的【" + gsc.getProviderNo() + "-" + gsc.getSampleNo() + "】的同步状态结束~~~");
            } catch (Exception e) {
                e.printStackTrace();
                logger.info("更新化检信息表 GJZ_SAMPLE_COLLECTION 中的【" + gsc.getProviderNo() + "-" + gsc.getSampleNo()
                        + "】的同步状态异常，异常信息：" + e.getMessage());
            }
        }

    }

    @Override
    public void doCollectionExec() throws Exception {
        Date now = new Date();
        String nowStr = DateTools.getInstance().dateFormat(now, "yyyy-MM-dd HH:mm:ss");
        Date nowZero = AdscmDateUtils.getFormateDate(now);
        String todaytime = DateTools.getInstance().dateFormat(now, "yyyy-MM-dd");
        Wrapper<ProviderCollection> providerCollectionWrapper =new EntityWrapper<>();
        providerCollectionWrapper.last("where  modifyTime >= synDate and modifyTime>="+todaytime);//查询当天记录
        List<ProviderCollection> providerCollections = providerCollectionMapper.selectList(providerCollectionWrapper);
        logger.info("待同步的供浆者采浆信息 记录数=" + providerCollections.size());
        List<ProviderCollection> successAp = new ArrayList<>();
        for (ProviderCollection providerCollection : providerCollections) {
            try {
                //查询基本信息
                ProviderInfo providerInfo = providerInfoMapper.selectById(providerCollection.getProviderNo());
                if (AdscmBaseUtils.getInstance().isNotEmpty(providerInfo,null)){
                }else {
                    logger.info("同步的供浆者【" + providerCollection.getProviderNo()+":"+providerCollection.getRegisterNo() + "】采浆信息失败，没有找到供浆者基本信息 ~~~");
                    continue;
                }
                //查询精英登记信息
                TProviderregister providerRegister = new TProviderregister();
                providerRegister.setProviderNo(providerInfo.getCardId());
                providerRegister.setSmallNo(providerCollection.getRegisterNo());
                List<TProviderregister> regList = tProviderregisterMapper.getProviderRegister(providerRegister);
                if (regList != null && regList.size() > 0) {
                    providerRegister = regList.get(0);
                } else {
                    logger.info("同步的供浆者【" + providerCollection.getProviderNo()+":"+providerCollection.getRegisterNo() + "】采浆信息失败，没有找到供浆者在精英的登记信息 ~~~");
                    continue;
                }
                //创建异常采浆记录
                ExceptionCollections exceptionCollections=new ExceptionCollections();
                exceptionCollections.setProviderNo(providerInfo.getCardId());
                exceptionCollections.setCollectionDate(todaytime);
                exceptionCollections.setMachineNo(providerCollection.getMachineNo());
                //查询采浆记录
                TCollectionrecord cRecord = new TCollectionrecord();
                cRecord.setProviderNo(providerInfo.getCardId());
                cRecord.setSmallNo(providerRegister.getSmallNo());
                List<TCollectionrecord> tcs = tCollectionrecordMapper.getCollectionRecord(cRecord);
                if (tcs != null && tcs.size() > 0) {
                    cRecord = tcs.get(0);
                }
                String factoryPlasmaNo = cRecord.getFactoryPlasmaNo();//
                if(AdscmBaseUtils.getInstance().isNotEmpty(factoryPlasmaNo,null)){
                    //证明已经生成了耗材记录了，就不要重复使用耗材了
                    cRecord.setIDNo(providerInfo.getIdNo());
                    cRecord.setAssayNo("0");// 化检编号

                    cRecord.setSmallNo(providerRegister.getSmallNo());
                    cRecord.setProviderNo(providerInfo.getCardId());

                    cRecord.setCollectionDate(AdscmDateUtils.getDateFomat(providerCollection.getCollectionDate()));
                    int worker = 0;
                    if (AdscmBaseUtils.getInstance().isNotEmpty(providerCollection.getNurse(),null)) {
                        worker = Integer.parseInt(providerCollection.getNurse());
                    }
                    cRecord.setIsCollection("1");
                    cRecord.setCollectionWorker(worker + "");// 护士ID
                    // cRecord.setPlasmano(pcode);//血浆编号
                    cRecord.setIsAuditing("1");
                    if (providerCollection.getTotalPlasmaNum() >= 590) {
                        cRecord.setPlasmaGross(600 + "");
                    } else {
                        cRecord.setPlasmaGross(providerCollection.getTotalPlasmaNum() + "");
                    }
                    long runtime = providerCollection.getCollTaken() / 60;
                    if(runtime > 100){
                        //大于100分钟
                        exceptionCollections.setCycleTimes(String.valueOf(runtime));
                        //如果得到的时间出现异常，那么自动生成一个基于 30 -- 50 之间的一个随机数 作为运行时间
                        runtime = new Random().nextInt(50 - 30 + 1) + 30;
                    }
                    cRecord.setCycleTimes(String.valueOf(providerCollection.getCycles()));
                    cRecord.setRunTime(String.valueOf(runtime));
                    cRecord.setAnticoagulant(Math.round(providerCollection.getUseKngNum()) + "");
                    cRecord.setBloodGross(providerCollection.getTotalBloodNum()+ "");

                    if(cRecord.getPlasmaGross().equals("600")){
                        if(runtime<20){
                            exceptionCollections.setRuntime(String.valueOf(runtime));
                            runtime=20;
                            cRecord.setRunTime(String.valueOf(runtime));
                        }

                        if(Math.round(providerCollection.getUseKngNum())<60||Math.round(providerCollection.getUseKngNum())>110){
                            exceptionCollections.setAnticoagulant(Math.round(providerCollection.getUseKngNum()) +"");
                            int anticoagulant=new Random().nextInt(10) +60;
                            cRecord.setAnticoagulant(anticoagulant+ "");
                        }
                        if(providerCollection.getTotalBloodNum()<1000){
                            exceptionCollections.setBloodGross(providerCollection.getTotalBloodNum()+"");
                            int BloodGross=new Random().nextInt(10) +1100;
                            cRecord.setBloodGross(BloodGross+"");
                        }
                        if(providerCollection.getCycles()<2){
                            exceptionCollections.setCycleTimes(providerCollection.getCycles()+"");
                            cRecord.setCycleTimes("2");
                        }
                    }




                    // 机器信息
                    cRecord.setMachineNo(providerCollection.getMachineNo());


                    cRecord.setMachineStatus("1");
                    if (providerCollection.getTotalPlasmaNum() >= 590) {
                        cRecord.setCollectionInstance("1");// 采浆量是否足够
                    } else {
                        cRecord.setCollectionInstance("0");// 采浆量是否足够
                    }
                    cRecord.setCJYZ("是");
                    cRecord.setCJJX("ZXDC");
                    cRecord.setRemark("");
                    if ( "1".equals( providerCollection.getIsDeal())  ) {
                        cRecord.setCollectionResult("1");
                    } else {
                        cRecord.setCollectionResult("0");
                    }
                    cRecord.setIF_GDJY(providerRegister.getIF_GDJY());
                    cRecord.setCollectiondate_info(nowStr);
                    tCollectionrecordMapper.updateCollectionRecord(cRecord);
                }else {

                    KHcsl hc = new KHcsl();
                    hc.setNumber("0");
                    hc.setMaterialNo("001");

                    KHcsl knj = new KHcsl();
                    knj.setNumber("0");
                    knj.setMaterialNo("002");

                    // 查找耗材和抗凝剂，按照入库的时间最早的查询
                    List<KHcsl> hc_list01 = kHcslMapper.getKHCSL(hc);
                    List<KHcsl> hc_list02 = kHcslMapper.getKHCSL(knj);

                    if (hc_list01 != null && hc_list01.size() > 0) {
                        hc = hc_list01.get(0);
                    }
                    if (hc_list02 != null && hc_list02.size() > 0) {
                        knj = hc_list02.get(0);
                    }
                    logger.info("查询精英的耗材：" + hc);
                    logger.info("查询精英的耗材：" + knj);

                    // 精英采浆记录
                    cRecord.setIDNo(providerInfo.getIdNo());
                    cRecord.setAssayNo("0");// 化检编号

                    cRecord.setSmallNo(providerRegister.getSmallNo());
                    cRecord.setProviderNo(providerInfo.getCardId());

                    cRecord.setCollectionDate(AdscmDateUtils.getDateFomat(providerCollection.getCollectionDate()));
                    int worker = 0;
                    if (AdscmBaseUtils.getInstance().isNotEmpty(providerCollection.getNurse(),null)) {

                        worker = Integer.parseInt(providerCollection.getNurse());
                    }
                    cRecord.setIsCollection("1");
                    cRecord.setCollectionWorker(worker + "");// 护士ID
                    // cRecord.setPlasmano(pcode);//血浆编号
                    cRecord.setIsAuditing("1");
                    if (providerCollection.getTotalPlasmaNum() >= 590) {
                        cRecord.setPlasmaGross(600 + "");
                    } else {
                        cRecord.setPlasmaGross(providerCollection.getTotalPlasmaNum() + "");
                    }
                    long runtime = providerCollection.getCollTaken()/ 60;
                    if(runtime > 100){
                        //如果得到的时间出现异常，那么自动生成一个基于 30 -- 50 之间的一个随机数 作为运行时间
                        runtime = new Random().nextInt(50 - 30 + 1) + 30;
                    }
                    cRecord.setCycleTimes(String.valueOf(providerCollection.getCycles()));
                    cRecord.setRunTime(String.valueOf(runtime));
                    cRecord.setAnticoagulant(Math.round(providerCollection.getUseKngNum()) + "");
                    cRecord.setBloodGross(providerCollection.getTotalBloodNum() + "");


                    if(cRecord.getPlasmaGross().equals("600")){
                        if(runtime<20){
                            exceptionCollections.setRuntime(String.valueOf(runtime));
                            runtime=20;
                            cRecord.setRunTime(String.valueOf(runtime));
                        }

                        if(Math.round(providerCollection.getUseKngNum())<60 || Math.round(providerCollection.getUseKngNum())>110){
                            exceptionCollections.setAnticoagulant(Math.round(providerCollection.getUseKngNum()) +"");
                            int anticoagulant=new Random().nextInt(10) +60;
                            cRecord.setAnticoagulant(anticoagulant+ "");
                        }
                        if(providerCollection.getTotalBloodNum()<1000){
                            exceptionCollections.setBloodGross(providerCollection.getTotalBloodNum()+"");
                            int BloodGross=new Random().nextInt(10) +1100;
                            cRecord.setBloodGross(BloodGross+"");
                        }
                        if(providerCollection.getCycles()<2){
                            exceptionCollections.setCycleTimes(providerCollection.getCycles()+"");
                            cRecord.setCycleTimes("2");
                        }
                    }



                    // 机器信息
                    cRecord.setMachineNo(providerCollection.getMachineNo());
                    cRecord.setMachineStatus("1");
                    if (providerCollection.getTotalPlasmaNum() >= 590) {
                        cRecord.setCollectionInstance("1");// 采浆量是否足够
                    } else {
                        cRecord.setCollectionInstance("0");// 采浆量是否足够
                    }
                    cRecord.setCJYZ("是");
                    if (hc != null && knj != null) {
                        cRecord.setFactoryPlasmaNo(hc.getHCBM() + "|" + knj.getHCBM());
                        cRecord.setTempletNovar(hc.getHCBM() + "" + knj.getHCBM());
                        logger.info("模板编号：" + cRecord.getTempletNovar());
                    }
                    cRecord.setCJJX("ZXDC");
                    cRecord.setRemark("");
                    if ("1".equals(providerCollection.getIsDeal())) {
                        cRecord.setCollectionResult("1");
                    } else {
                        cRecord.setCollectionResult("0");
                    }
                    cRecord.setIsAuditing("0");
                    cRecord.setAssessor("0");

                    String d = DateTools.getInstance().dateFormat(new Date(0L), "yyyy-MM-dd");
                    cRecord.setOrg_id("0");
                    cRecord.setUpdate_flag("2");
                    cRecord.setUpdate_date(d);
                    cRecord.setWeb_flag("-1");

                    cRecord.setOrg_id_SW("0");
                    cRecord.setUpdate_flag_SW("2");
                    cRecord.setUpdate_date_SW(d);
                    cRecord.setWeb_flag_SW("-1");

                    cRecord.setOrg_id_QT("0");
                    cRecord.setUpdate_flag_QT("2");
                    cRecord.setUpdate_date_QT(d);
                    cRecord.setWeb_flag_QT("-1");

                    cRecord.setIF_GDJY(providerRegister.getIF_GDJY());
                    cRecord.setCollectiondate_info(nowStr);

                    logger.info("回写精英采浆结束 ，登记号：" + providerRegister.getSmallNo());

                    // 回写建档记录中的最后采浆日期 总浆数加加一
                    TProviderbaseinfo base = new TProviderbaseinfo();
                    base.setProviderNo(providerInfo.getCardId());

                    List<TProviderbaseinfo> baseList = tProviderbaseinfoMapper.getProviderBaseInfo(base);

                    if (baseList != null && baseList.size() == 1) {
                        base = baseList.get(0);
                        base.setCollectionDate(DateTools.getInstance().dateFormatZero(nowStr));
                        Calendar next_day = Calendar.getInstance();
                        next_day.setTime(now);
                        next_day.add(Calendar.DAY_OF_YEAR, 14);

                        base.setLastDateBooking(DateTools.getInstance().dateFormat(next_day.getTime(), "yyyy-MM-dd"));
                        logger.info("回写建档记录中【" + providerInfo.getName() + "】的最后采浆日期为今天！");
                        //总采浆次数加1
                        base.setTimes( String.valueOf(Integer.valueOf(base.getTimes())+1));
                        logger.info("回写建档记录中【" + providerInfo.getName() + "】的总采浆次数"+base.getTimes());
                    }

                    logger.info("写精英的耗材使用量  start");

                    KUse kuse = new KUse();
                    KUseList uList_1 = new KUseList();

                    String nullDate = DateTools.getInstance().dateFormat(now, "yyyy-MM-dd");
                    String useno = "S" + DateTools.getInstance().dateFormat(now, "yyMMdd") + "0001";
                    kuse.setUseNo(useno);
                    kuse.setDepotNo(1+"");
                    kuse.setUseDate(nullDate);
                    kuse.setRemark("采浆模块使用耗材");
                    kuse.setIfFlow("1");
                    kuse.setModeUser("采浆");
                    kuse.setIsAuditing("0");
                    kuse.setAssessor("0");
                    kuse.setDepotNo("1");
                    kuse.setOrg_id("028008002001");
                    kuse.setUpdate_flag("1");
                    kuse.setUpdate_date(DateTools.getInstance().dateFormatZero("1905-03-14 00:00:00"));
                    kuse.setWeb_flag("-1");
                    kuse.setOrg_id_SW("0");
                    kuse.setUpdate_flag_SW("-1");
                    kuse.setUpdate_date_SW(DateTools.getInstance().dateFormatZero("1900-01-01 00:00:00"));
                    kuse.setWeb_flag_SW("-1");
                    kuse.setOrg_id_QT("0");
                    kuse.setUpdate_flag_QT("1");
                    kuse.setUpdate_date_QT(DateTools.getInstance().dateFormatZero("1900-01-01 00:00:00"));
                    kuse.setWeb_flag_QT("-1");

                    uList_1.setDepotNo(useno);
                    uList_1.setMaterialNo(hc.getMaterialNo());
                    uList_1.setPH(hc.getPH());
                    uList_1.setUnits(hc.getUnits());
                    uList_1.setNumber("1");
                    uList_1.setDepotNo("1");
                    uList_1.setIfOut("0");
                    uList_1.setXQ(hc.getXQ());
                    uList_1.setBegDate(hc.getBegDate());
                    uList_1.setEndDate(hc.getEndDate());
                    uList_1.setRemark("采浆模块使用耗材");
                    uList_1.setOperateDate(nullDate);
                    uList_1.setProviderNo(providerInfo.getCardId());

                    JyUser jyUser = jyUserMapper.selectById(providerCollection.getNurse());
                    String optionerName = "";// 操作员
                    if (AdscmBaseUtils.getInstance().isNotEmpty(jyUser,null)) {
                        optionerName = jyUser.getName();
                    }

                    uList_1.setOperater(optionerName);
                    uList_1.setSmallno(cRecord.getCollectionNo() + "");
                    uList_1.setModeUser("采浆");

                    KUseList uList_2 = new KUseList();
                    uList_2.setUseNo(useno);
                    uList_2.setMaterialNo(knj.getMaterialNo());
                    uList_2.setPH(knj.getPH());
                    uList_2.setUnits(knj.getUnits());
                    uList_2.setNumber("1");
                    uList_2.setDepotNo("1");
                    uList_2.setIfOut("0");
                    uList_2.setXQ(knj.getXQ());
                    uList_2.setBegDate(knj.getBegDate());
                    uList_2.setEndDate(knj.getEndDate());
                    uList_2.setRemark("采浆模块使用耗材");
                    uList_2.setOperateDate(nullDate);
                    uList_2.setProviderNo(providerInfo.getCardId());
                    uList_2.setOperater(optionerName);
                    uList_2.setSmallno(cRecord.getCollectionNo() + "");
                    uList_2.setModeUser("采浆");

                    String hc_num = hc.getNumber();// 耗材剩余量

                    int num = Integer.parseInt(hc_num.substring(0, hc_num.indexOf(".")));
                    hc.setNumber((num - 1) + "");

                    String knj_num = knj.getNumber();// 抗凝剂剩余量

                    num = Integer.parseInt(knj_num.substring(0, knj_num.indexOf(".")));
                    knj.setNumber((num - 1) + "");

                    logger.info("写精英的耗材使用量  end");

                    // 回写精英登记表
                    providerRegister.setIsCollection("1");
                    tProviderregisterMapper.updateProviderRegister(providerRegister);
                    if (cRecord.getCollectionResult() == "1") {

                        logger.info("写精英的日志：采浆记录  start");

                        try {
                            Systemlogjiaying sysLog = new Systemlogjiaying();
                            Systemlogjiaying sysLog2 = new Systemlogjiaying();

                            String modeName = "采浆记录";

                            sysLog.setModeName(modeName);
                            String optionInfo = "操作员：" + optionerName + " 把供浆员：" + providerInfo.getName() + "，编号为：" + providerInfo.getCardId()
                                    + "采浆预约日期修改为：" + nullDate;
                            sysLog.setOptioninfo(optionInfo);
                            sysLog.setOptionter(worker + "");
                            sysLog.setOptionterdate(now);
                            sysLog.setOptdate(now);
                            sysLog.setOptdate(nowZero);

                            sysLog.setDelbat("0");
                            sysLog.setSynDate(nowZero);
                            sysLog.setModifyTime(now);

                            sysLog2.setModeName(modeName);
                            String optionInfo1 = "操作员：" + optionerName + " 把供浆员：" + providerInfo.getName() + "，编号为：" + providerInfo.getCardId()
                                    + "采浆为：合格";
                            sysLog2.setOptioninfo(optionInfo1);
                            sysLog2.setOptionter(worker + "");
                            sysLog2.setOptionterdate(now);
                            sysLog2.setOptdate(now);
                            sysLog2.setOptdate(nowZero);
                            sysLog2.setSynDate(nowZero);
                            sysLog2.setModifyTime(now);
                            sysLog2.setDelbat("0");
                            systemlogjiayingMapper.insert(sysLog);
                            systemlogjiayingMapper.insert(sysLog2);

                        } catch (Exception e) {
                            logger.info("写精英的日志：采浆记录  异常：" + e.getMessage());
                        }
                        logger.info("写精英的日志：采浆记录  end");
                        kUseListMapper.addKUSEList(uList_1);
                        kUseListMapper.addKUSEList(uList_2);
                        kHcslMapper.updateKHCSL(hc);
                        kHcslMapper.updateKHCSL(knj);
                        kUseMapper.addKUSE(kuse);
                        kUseMapper.addKUSE(kuse);

                        tProviderbaseinfoMapper.updateProviderBaseInfo(base);

                    }

                    //保存异常采浆记录
                    if (exceptionCollections.getAnticoagulant()!=null||exceptionCollections.getBloodGross()!=null||
                            exceptionCollections.getCycleTimes()!=null||exceptionCollections.getRuntime()!=null) {
                        exceptionCollectionsMapper.insert(exceptionCollections);
                    }

                    if (cRecord.getCollectionNo() != null && !"".equals(cRecord.getCollectionNo())) {
                        tCollectionrecordMapper.updateCollectionRecord(cRecord);
                    } else {
                        tCollectionrecordMapper.addCollectionRecord(cRecord);
                    }

                }
                successAp.add(providerCollection);
                Systemlogjiaying  sysLog =new Systemlogjiaying();
                Systemlogjiaying  sysLog2 =new Systemlogjiaying();
                JyUser jyUser = jyUserMapper.selectById(providerCollection.getNurse());
                String  optionerName="";
                if (AdscmBaseUtils.getInstance().isNotEmpty(jyUser,null)){
                    optionerName=jyUser.getName();

                }
                //新增日志信息
                sysLog.setModeName("采浆记录");
                String time = new SimpleDateFormat("yyyy-MM-dd").format(providerCollection.getCollectionDate());
                String optionInfo="操作员："+optionerName+" 把供浆员："+providerInfo.getName()+"，编号为："+providerInfo.getCardId()+"采浆预约日期修改为："+time;
                sysLog.setOptioninfo(optionInfo);
                sysLog.setOptionter(providerCollection.getNurse());
                sysLog.setOptionterdate(providerCollection.getEndTime());
                sysLog.setOptdate(providerCollection.getCollectionDate());

                sysLog.setDelbat("0");
                sysLog.setSynDate(DateTools.getInstance().setZeroTime(new Date()));
                sysLog.setModifyTime(new Date());

                sysLog2.setModeName("采浆记录");
                String optionInfo1="操作员："+optionerName+" 把供浆员："+providerInfo.getName()+"，编号为："+providerInfo.getCardId()+"采浆为：合格";
                sysLog2.setOptioninfo(optionInfo1);
                sysLog2.setOptionter(providerCollection.getNurse());
                sysLog2.setOptionterdate(providerCollection.getEndTime());
                sysLog2.setOptdate(providerCollection.getCollectionDate());
                sysLog2.setSynDate(DateTools.getInstance().setZeroTime(new Date()));
                sysLog2.setModifyTime(new Date());
                sysLog2.setDelbat("0");
                  systemlogjiayingMapper.insert(sysLog2);
                  systemlogjiayingMapper.insert(sysLog);

                logger.info("同步的供浆者【" + providerCollection.getProviderNo() +":"+ providerCollection.getRegisterNo()+ "】采浆信息结束~~~");
            }catch (Exception e){
                e.printStackTrace();
                logger.info("同步的供浆者【" +providerCollection.getProviderNo() +":"+ providerCollection.getRegisterNo()+ "】采浆信息异常，异常信息：" + e.getMessage());
            }
        }
        // 更新佳颖数据库中的同步时间

        for (ProviderCollection providerCollection : successAp) {
            try {
                logger.info("更新同步供浆者【" + providerCollection.getProviderNo() +":"+ providerCollection.getRegisterNo() + "】采浆信息的同步状态开始~~~");

                providerCollection.setSynDate(now);
                // 这里将同步时间修改为现在
                providerCollectionMapper.updateById(providerCollection);

                logger.info("更新同步的供浆者【" + providerCollection.getProviderNo() +":"+ providerCollection.getRegisterNo() + "】采浆信息的同步状态结束~~~");
            } catch (Exception e) {
                e.printStackTrace();
                logger.info("更新供浆者【" + providerCollection.getProviderNo() +":"+ providerCollection.getRegisterNo() + "】采浆信息的同步状态异常，异常信息：" + e.getMessage());
            }
        }
    }

    @Override
    public void doCostExec() throws Exception {
        Date now = new Date();
        String nowStr = DateTools.getInstance().dateFormat(now, "yyyy-MM-dd HH:mm:ss");
        String nowStrZero = DateTools.getInstance().dateFormat(now, "yyyy-MM-dd");
        Date nowZero = AdscmDateUtils.getFormateDate(now);
        //查询待同步的费用记录
        Wrapper<ProviderCost> providerCostWrapper=new EntityWrapper<>();
        providerCostWrapper.last("where  modifyTime >= synDate and modifyTime >="+nowStrZero);// 最佳是加上一个查询当天的  modifyTime >=nowStrZero
        List<ProviderCost> providerCosts = providerCostMapper.selectList(providerCostWrapper);
        logger.info("待同步的供浆者费用发放信息 记录数=" + providerCosts.size());
        List<ProviderCost> successCost = new ArrayList<>();

        for (ProviderCost providerCost : providerCosts) {
            try {
                ProviderInfo providerInfo = providerInfoMapper.selectById(providerCost.getProviderNo());
                if (AdscmBaseUtils.getInstance().isNotEmpty(providerInfo,null)){

                }else {
                    logger.info("同步的供浆者【" + providerCost.getProviderNo()+":"+providerCost.getRegisterNo() + "】费用信息失败，没有找到供浆者基本信息 ~~~");
                    continue;
                }
                TProviderregister providerRegister = new TProviderregister();
                providerRegister.setSmallNo(providerCost.getRegisterNo());
                providerRegister.setProviderNo(providerInfo.getCardId());
                List<TProviderregister> regList = tProviderregisterMapper.getProviderRegister(providerRegister);
                if (regList != null && regList.size() > 0) {
                    providerRegister = regList.get(0);
                } else {
                    logger.info("同步的供浆者【" + providerCost.getProviderNo()+":"+providerCost.getRegisterNo()+ "】费用信息失败，没有找到供浆者在精英的登记信息 ~~~");
                    continue;
                }
                // 精英费用发放记录
                TCollectionrecord collection = new TCollectionrecord();
                collection.setProviderNo(providerInfo.getCardId());
                collection.setSmallNo(providerRegister.getSmallNo());

                List<TCollectionrecord> collections = tCollectionrecordMapper.getCollectionRecord(collection);
                String collectionNo = "0";
                if (collections != null && collections.size() == 1) {
                    collection = collections.get(0);
                    collectionNo = collection.getCollectionNo();
                }

                if(  !"1".equals(collection.getIsCollection())){
                    logger.info("同步的供浆者【" + providerCost.getProviderNo()+":"+providerCost.getRegisterNo()+ "】费用信息失败，没有找到供浆者在精英的采浆信息 ~~~");
                    continue;
                }
                //查询费用信息
                TRaterecord rr = new TRaterecord();
                rr.setProviderNo(providerInfo.getCardId());
                rr.setSmallNo(providerRegister.getSmallNo());
                List<TRaterecord> rrs = tRaterecordMapper.getRateRecord(rr);
                if (rrs != null && rrs.size() > 0) {
                    rr = rrs.get(0);
                }else{
                    rr.setCollectionNo(collectionNo);

                    String nullDate = DateTools.getInstance().dateFormat(new Date(0L), "yyyy-MM-dd");

                    rr.setIsAuditing("0");
                    rr.setAssessor("0");
                    rr.setOrg_id("0");
                    rr.setUpdate_flag("2");
                    rr.setUpdate_date(nullDate);
                    rr.setWeb_flag("-1");
                    rr.setOrg_id_SW("0");
                    rr.setUpdate_flag_SW("2");
                    rr.setUpdate_date_SW(nullDate);
                    rr.setWeb_flag_SW("-1");
                    rr.setOrg_id_QT("0");
                    rr.setUpdate_flag_QT("2");
                    rr.setUpdate_date_QT(nullDate);
                    rr.setWeb_flag_QT("-1");
                    rr.setYQ_FY("0.0");
                    rr.setTM_FY("0.0");
                    rr.setCjcsbtje("0.0");
                    rr.setLJWFBTJE("0.0");
                    rr.setBus_KM("0.0");
                    rr.setAXKZS("0");
                    rr.setAXDHJE("0.0");
                    rr.setDHJQJE("0.0");
                    rr.setDs_YYCF("0.0");
                    rr.setJSR_FY("0.0");
                    rr.setWGBT_RNMTBSW("0.0");
                    rr.setRnmlskk("0.0");
                }

                rr.setIF_GDJY(providerRegister.getIF_GDJY());

                if (providerCost.getState() != null && "1".equals(providerCost.getState())) {
                    providerRegister.setIsRate("1");
                    rr.setPutOutDate(AdscmDateUtils.getDateFomat(providerCost.getPutOutDate()));
                    rr.setIsPutOut("1");
                }else{
                    rr.setIsPutOut("0");
                }

                rr.setIDNo(providerInfo.getIdNo());
                rr.setProviderNo(providerInfo.getCardId());
                rr.setSmallNo(providerRegister.getSmallNo());
                rr.setCollectionDate(collection.getCollectionDate());
                rr.setPutOutMoney(providerCost.getPutOutMoney()+"");
                rr.setTMMoney("0.0");
                rr.setCjcsbtje(providerCost.getTimesAllowance() +"");

                int worker = 0;
                if (AdscmBaseUtils.getInstance().isNotEmpty(providerCost.getPutWorker(),null)) {

                    worker = Integer.parseInt(providerCost.getPutWorker());
                }
                rr.setPutWorker(worker+"");
                rr.setBase_FY(providerCost.getBaseMoney()+"");
                rr.setTrafficFee(providerCost.getTrafficFee()+"");
                rr.setPlasmaGross(collection.getPlasmaGross());
                rr.setCollectionWorker(collection.getCollectionWorker());
                tProviderregisterMapper.updateProviderRegister(providerRegister);
                if(rr.getSerial() != null && !"".equals(rr.getSerial())){
                    tRaterecordMapper.updateRateRecord(rr);
                }else{
                    tRaterecordMapper.addRateRecord(rr);
                }

                successCost.add(providerCost);
                // 费用发放日志

                 String optionerName="";
                JyUser jyUser = jyUserMapper.selectById(providerCost.getPutWorker());
                if (AdscmBaseUtils.getInstance().isNotEmpty(jyUser,null)){
                    optionerName=jyUser.getName();
                }
                Systemlogjiaying  sysLog=new Systemlogjiaying();
                sysLog.setModeName("营养费发放");
                String optionInfo="操作员："+optionerName+"把供浆员："+providerInfo.getName()+"，编号为："+providerInfo.getCardId()+" 营养费发成："+providerCost.getPutOutMoney()+"元！";
                sysLog.setOptioninfo(optionInfo);
                sysLog.setOptionter(providerCost.getPutWorker());
                sysLog.setOptionterdate(providerCost.getEndTime());
                Date setZeroTime = DateTools.getInstance().setZeroTime(providerCost.getEndTime());
                sysLog.setOptdate(setZeroTime);
                sysLog.setSynDate(DateTools.getInstance().setZeroTime(new Date()));
                sysLog.setModifyTime(new Date());
                sysLog.setDelbat("0");
                systemlogjiayingMapper.insert(sysLog);
                logger.info("费用发放日志【" +  providerCost.getProviderNo()+":"+providerCost.getRegisterNo() + "】添加~~~");

                logger.info("同步的供浆者【" +  providerCost.getProviderNo()+":"+providerCost.getRegisterNo() + "】费用信息结束~~~");

            }catch (Exception e){
                e.printStackTrace();
                logger.info("同步的供浆者【" + providerCost.getProviderNo()+":"+providerCost.getRegisterNo() + "】费用信息异常，异常信息：" + e.getMessage());
            }
        }

        for (ProviderCost providerCost : successCost) {

            try {
                logger.info("更新同步的供浆者【" +  providerCost.getProviderNo()+":"+providerCost.getRegisterNo() + "】费用信息的同步状态开始~~~");

                providerCost.setSynDate(new Date());
                // 这里将同步时间修改为现在
                providerCostMapper.updateById(providerCost);
                logger.info("更新同步的供浆者【" +  providerCost.getProviderNo()+":"+providerCost.getRegisterNo()  + "】费用信息的同步状态结束~~~");
            } catch (Exception e) {
                e.printStackTrace();
                logger.info("更新供浆者【" +  providerCost.getProviderNo()+":"+providerCost.getRegisterNo() + "】费用信息的同步状态异常，异常信息：" + e.getMessage());
            }


        }

    }

    @Override
    public void doHeatExec() throws Exception {
        Date now = new Date();
        String nowStr = DateTools.getInstance().dateFormat(now, "yyyy-MM-dd HH:mm:ss");
        String nowStrZero = DateTools.getInstance().dateFormat(now, "yyyy-MM-dd");
        HeatSeal gHeat = new HeatSeal();
        gHeat.setMODIFY_TIME(nowStr);

        Wrapper<HeatSeal> wrapper=new EntityWrapper<>();
//        wrapper.eq("MODIFY_TIME",nowStr).lt("createTime",nowStrZero);
        wrapper.last(" where  modify_time >= syndate and modify_time >= "+nowStrZero);// 最佳是加上一个查询当天的  modifyTime >=nowStrZero
        List<HeatSeal> heatList = heatSealMapper.selectList(wrapper);

        logger.info("待同步的血浆热合信息 记录数=" + heatList.size());

        List<HeatSeal> successHeat = new ArrayList<HeatSeal>();

        for (HeatSeal heat : heatList) {
            try {
                ProviderInfo gjz = new ProviderInfo();
                gjz.setId(Long.valueOf(heat.getProviderNo()));
                List<ProviderInfo> gjzList = providerInfoMapper.getGJZXX(gjz);
                if (gjzList != null && gjzList.size() > 0) {
                    gjz = gjzList.get(0);
                } else {
                    logger.info("同步的供浆者【" + heat.getProviderNo() + "】热合信息失败，没有找到供浆者基本信息 ~~~");
                    continue;
                }
                TProviderregister providerRegister = new TProviderregister();
                providerRegister.setRegistDate(nowStrZero);
                providerRegister.setIDNo(gjz.getIdNo());
                List<TProviderregister> regList = tProviderregisterMapper.getProviderRegister(providerRegister);
                if (regList != null && regList.size() > 0) {
                    providerRegister = regList.get(0);
                } else {
                    logger.info("同步的供浆者【" + heat.getProviderNo() + "】热合信息失败，没有找到供浆者在精英的登记信息 ~~~");
                    continue;
                }

                TCollectionrecord collection = new TCollectionrecord();
                collection.setProviderNo(gjz.getCardId());
                collection.setSmallNo(providerRegister.getSmallNo());

                List<TCollectionrecord> collections = tCollectionrecordMapper.getCollectionRecord(collection);
                if (collections != null && collections.size() == 1) {
                    collection = collections.get(0);
                }

                if(!"1".equals(collection.getIsCollection())){
                    logger.info("同步的供浆者【" + heat.getProviderNo() + "】热合信息失败，没有找到供浆者在精英的采浆信息 ~~~");
                    continue;
                }


                TPlasmstock tps = new TPlasmstock();
                tps.setSmallNo(providerRegister.getSmallNo());
                List<TPlasmstock> tpss = tPlasmstockabcMapper.getPlasmStock(tps);

                if (tpss != null && tpss.size() > 0) {

                }else{
                    tps.setCollectionNo("0");// 这个是0，就是待办的，就会显示到精英系统界面的左边
                    tps.setIsOut("1");//检疫期数据设置成1才能查看到
                    tps.setIsAuditing("0");
                    tps.setAssessor("0");
                    tps.setOrg_id("0");
                    tps.setUpdate_flag("2");
                    tps.setUpdate_date(DateTools.getInstance().dateFormatZero("1900-01-01 00:00:00"));
                    tps.setWeb_flag("-1");
                    tps.setIssep("0");
                    tps.setOrg_id_SW("0");
                    tps.setUpdate_flag_SW("2");
                    tps.setUpdate_date_SW(DateTools.getInstance().dateFormatZero("1900-01-01 00:00:00"));
                    tps.setWeb_flag_SW("-1");
                    tps.setOrg_id_QT("0");
                    tps.setUpdate_flag_QT("2");
                    tps.setUpdate_date_QT(DateTools.getInstance().dateFormatZero("1900-01-01 00:00:00"));
                    tps.setWeb_flag_QT("-1");
                    tps.setIF_GDJY(providerRegister.getIF_GDJY());
                    tps.setProviderNoType("1");
                    tps.setAvalue("0.0");

                    tps.setPlasmaType("1");
                    tps.setIDNo(gjz.getIdNo());
                    tps.setProviderNo(gjz.getCardId());
                    tps.setSmallNo(providerRegister.getSmallNo());
                    tps.setCollectionDate(collection.getCollectionDate());
                    tps.setCollectionTime(collection.getCollectiondate_info());
                    tps.setCollectionWorker(collection.getCollectionWorker());
                    tps.setInPacker("0");
                    // 采浆量
                    tps.setPlasmaGross(collection.getPlasmaGross());

                    tPlasmstockabcMapper.addPlasmStock(tps);

                    logger.info("保存精英热合信息结束");
                }
                successHeat.add(heat);
                logger.info("同步血浆【" + heat.getSealId() + "】热合信息结束~~~");
            } catch (Exception e) {
                e.printStackTrace();
                logger.info("同步的血浆【" + heat.getSealId() + "】热合信息异常，异常信息：" + e.getMessage());
            }
        }
        // 更新佳颖数据库中的同步时间
        for (HeatSeal heat : successHeat) {
            try {
                logger.info("更新同步血浆【" + heat.getSealId() + "】热合信息的同步状态开始~~~");

                heat.setSYNDATE(nowStr);
                // 这里将同步时间修改为现在
                heatSealMapper.updateById(heat);
                logger.info("更新同步血浆【" + heat.getSealId() + "】热合信息的同步状态结束~~~");
            } catch (Exception e) {
                e.printStackTrace();
                logger.info("更新同步血浆【" + heat.getSealId() + "】热合信息的同步状态异常，异常信息：" + e.getMessage());
            }
        }
    }

    @Override
    public void doXpExec() throws Exception {
        Date now = new Date();
        SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd");
        String nowStr = DateTools.getInstance().dateFormat(now, "yyyy-MM-dd HH:mm:ss");

        ProviderXp gCheck = new ProviderXp();
        gCheck.setMODIFY_TIME(nowStr);
        List<ProviderXp> xpList = providerXpMapper.selectByXPCheck(gCheck );

        logger.info("待同步的供浆者胸片信息 记录数=" + xpList.size());

        List<ProviderXp> successXp = new ArrayList<>();//

        for (ProviderXp xp : xpList) {

            try {
                logger.info("同步的供浆者【" + xp.getProviderNo() + "】胸片信息开始~~~");

                ProviderInfo gjz = new ProviderInfo();
                gjz.setId(Long.valueOf(xp.getProviderNo()));
                List<ProviderInfo> gjzList = providerInfoMapper.getGJZXX(gjz);
                if (gjzList != null && gjzList.size() > 0) {
                    gjz = gjzList.get(0);
                } else {
                    logger.info("同步的供浆者【" + xp.getProviderNo() + "】胸片信息失败，没有找到供浆者基本信息 ~~~");
                    continue;
                }



                if (xp.getCreateDate() != null && !"".equals(xp.getCreateDate())) {

//                    String xtsj = DateTools.getInstance().dateFormatZero(xp.getCreateDate());
                    String xtsj = dateFormat.format(xp.getCreateDate());
                    TBodychecklastrecord tl = new TBodychecklastrecord();
                    tl.setProviderNo(gjz.getCardId());
                    tl.setXTSJ(xtsj);
                    List<TBodychecklastrecord> bcList = tBodychecklastrecordMapper.getBodyCheckLastRecord(tl);

                    boolean flag = false;
                    if (bcList != null && bcList.size() > 0) {
                        tl = bcList.get(0);
                        flag = true;
                    }

                    tl.setProviderNo(gjz.getCardId());
                    tl.setLastbodycheckdate(xtsj);
                    int worker = 10;
                    if (xp.getCrearor() != null && !"".equals(xp.getCrearor()) && xp.getCrearor().length() > 3) {
                        if (NumberTools.getInstance().isNumeric2(xp.getCrearor().substring(3))) {
                            worker = Integer.parseInt(xp.getCrearor().substring(3));
                        }
                    }
                    tl.setLastbodychecker(worker+"");
                    tl.setXTSJ(xtsj);
                    tl.setXTYS(xp.getDoctor());
                    tl.setXTDW(xp.getHospital());
                    tl.setOrg_id("0");
                    tl.setUpdate_flag("2");
                    tl.setUpdate_date(DateTools.getInstance().dateFormatZero("1900-01-01 00:00:00"));
                    tl.setWeb_flag("-1");
                    tl.setOrg_id_SW("0");
                    tl.setUpdate_flag_SW("2");
                    tl.setUpdate_date_SW(DateTools.getInstance().dateFormatZero("1900-01-01 00:00:00"));
                    tl.setWeb_flag_SW("-1");
                    tl.setOrg_id_QT("0");
                    tl.setUpdate_flag_QT("2");
                    tl.setUpdate_date_QT(DateTools.getInstance().dateFormatZero("1900-01-01 00:00:00"));
                    tl.setWeb_flag_QT("-1");

                    int sftg = Integer.valueOf(xp.getResult());
                    if (sftg == 1) {
                        tl.setXTGG("合格");
                    } else {
                        tl.setXTGG("不合格");
                    }

                    if(flag){
                        tBodychecklastrecordMapper.updateBodyCheckLastRecord(tl);
                    }else{
                        tBodychecklastrecordMapper.addBodyCheckLastRecord(tl);
                    }
                    successXp.add(xp);
                }

                logger.info("同步的供浆者【" + xp.getProviderNo() + "】胸片信息结束~~~");
            } catch (Exception e) {
                e.printStackTrace();
                logger.info("同步的供浆者【" + xp.getProviderNo() + "】胸片信息异常，异常信息：" + e.getMessage());
            }
        }
        // 更新佳颖数据库中的同步时间
        for (ProviderXp xp : successXp) {
            try {
                logger.info("更新同步的供浆者【" + xp.getProviderNo() + "】胸片信息的同步状态开始~~~");

                xp.setSYNDATE(nowStr);
                // 这里将同步时间修改为现在
                providerXpMapper.updateById(xp);
                logger.info("更新同步的供浆者【" + xp.getProviderNo() + "】胸片信息的同步状态结束~~~");
            } catch (Exception e) {
                e.printStackTrace();
                logger.info("更新供浆者【" + xp.getProviderNo() + "】胸片信息的同步状态异常，异常信息：" + e.getMessage());
            }
        }
    }

    @Override
    public void doLogExec() throws Exception {
        Date now = new Date();
        String nowStr = DateTools.getInstance().dateFormat(now, "yyyy-MM-dd HH:mm:ss");
        String zero = AdscmDateUtils.getDateFormat(now);
        Wrapper<Systemlogjiaying> systemlogjiayingWrapper =new EntityWrapper<>();
        systemlogjiayingWrapper.last("where  modifyTime >= synDate and modifyTime>="+zero);//查询当天的
        List<Systemlogjiaying> systemlogjiayings = systemlogjiayingMapper.selectList(systemlogjiayingWrapper);
        List<Systemlogjiaying>  successLog =new ArrayList<>();
        logger.info("待同步的供浆者日志信息 记录数=" + systemlogjiayings.size());
        for (Systemlogjiaying systemlogjiaying : systemlogjiayings) {
            try {
                SysOptionter sysOptionter = new SysOptionter();
                sysOptionter.setModeName(systemlogjiaying.getModeName());
                sysOptionter.setOptioninfo(systemlogjiaying.getOptioninfo());
                sysOptionter.setOptionter(systemlogjiaying.getOptionter());
                sysOptionter.setOptionterdate( AdscmDateUtils.getDateFomat(systemlogjiaying.getOptionterdate()) );
                sysOptionter.setOptdate( AdscmDateUtils.getNowOnlyDateFomat1(systemlogjiaying.getOptdate()));
                sysOptionter.setDelbat("0");
                sysOptionterMapper.addSystemLog(sysOptionter);
                successLog.add(systemlogjiaying);
                logger.info("同步的供浆者【" + systemlogjiaying.getOptionID() + "】日志信息结束~~~");

            }catch (Exception e){
                logger.info("同步的供浆者【" + systemlogjiaying.getOptionID() + "】日志信息异常，异常信息：" + e.getMessage());
            }
        }
        for (Systemlogjiaying systemlogjiaying : successLog) {
            try {
                logger.info("更新同步的供浆者【" + systemlogjiaying.getOptionID() + "】日志信息的同步状态开始~~~");

                systemlogjiaying.setSynDate(now);
                // 这里将同步时间修改为现在
                systemlogjiayingMapper.updateById(systemlogjiaying);
                logger.info("更新同步的供浆者【" + systemlogjiaying.getOptionID() + "】日志信息的同步状态结束~~~");
            } catch (Exception e) {
                e.printStackTrace();
                logger.info("更新供浆者【" + systemlogjiaying.getOptionID() + "】日志信息的同步状态异常，异常信息：" + e.getMessage());
            }
        }




    }

}


